使用用户名和密码隐藏进程的窗口

时间:2018-02-14 15:52:24

标签: c# winforms process

我试图在我的C#windows窗体应用程序上使用wmic.exe获取命令结果。我在我的代码中实现了它,但是当我调用我的函数时,我想要隐藏打开半秒然后关闭的窗口。 这是代码:

Process p = new Process();
p.StartInfo.FileName = "wmic.exe";
p.StartInfo.Arguments = "A COMMAND";
p.StartInfo.UserName = "";
SecureString secure = new SecureString();
foreach (char c in "")
{
    secure.AppendChar(c);
}
p.StartInfo.Password = secure;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
return output;

0 个答案:

没有答案