gpt4 book ai didi

c# - 使用不同用户名的 Processstartinfo 时隐藏控制台窗口

转载 作者:行者123 更新时间:2023-11-30 16:15:33 28 4
gpt4 key购买 nike

我正在使用特殊的用户、域和密码启动一个进程。虽然我告诉 C# 隐藏它显示的控制台窗口。

这是我的代码:

Process process = new Process();
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

process.StartInfo.UserName = strUsername;
process.StartInfo.Domain = strDomain;
process.StartInfo.Password = secPassword;

process.StartInfo.FileName = "PsExec.exe";
process.StartInfo.Arguments = @"/accepteula -s \\" + strServername + @"program.exe";
process.Start();
process.WaitForExit();

我可以在另一个论坛中找到一些提示:

If you call the Start(ProcessStartInfo) method with the ProcessStartInfo..::.UserName and ProcessStartInfo..::.Password properties set, the unmanaged CreateProcessWithLogonW function is called, which starts the process in a new window even if the CreateNoWindow property value is true or the WindowStyle property value is Hidden.

其实我对这个说法不是很满意...

提前致谢。

干杯亚历克斯

最佳答案

据我所知,此问题有解决方法。您可以使用参数启动隐藏的 cmd。像这样:

 ProcessStartInfo psi = new ProcessStartInfo("cmd.exe", String.Format("/accepteula -s \\{0}program.exe", strServername));
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
Process.Start(psi);

关于c# - 使用不同用户名的 Processstartinfo 时隐藏控制台窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19446021/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com