简体   繁体   English

禁止psexec命令窗口?

[英]Suppress psexec command windows?

In the application that I'm working on, everything works great. 在我正在处理的应用程序中,一切正常。 My question, is there a way to suppress the command windows when executing psexec? 我的问题是,执行psexec时是否有一种抑制命令窗口的方法? I want this to run silently. 我希望它静默运行。 Below is the code that I'm using.. I've read many examples online but nothing seems to be working. 下面是我正在使用的代码。我已经在线阅读了许多示例,但似乎没有任何效果。 Thoughts? 思考? Thanks. 谢谢。

            Process p = new Process();
            try
            {
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.RedirectStandardInput = true;                                      
                p = Process.Start(psExec, psArguments);
                if (p != null)
                {
                    string output = p.StandardOutput.ReadToEnd();
                    string error = p.StandardError.ReadToEnd();
                    p.WaitForExit();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (p != null)
                {
                    p.Dispose();
                }
            }

You're setting the StartInfo before actually assigning the p variable again, your code would have to look like this: 您在实际再次分配p变量之前设置StartInfo,您的代码必须如下所示:

...
ProcessStartInfo startinfo = new ProcessStartInfo(psExec, psArguments);
startinfo.UseShellExecute = false;
startinfo.CreateNoWindow = true;
startinfo.WindowStyle = ProcessWindowStyle.Hidden;
startinfo.RedirectStandardOutput = true;
startinfo.RedirectStandardError = true;
startinfo.RedirectStandardInput = true;                                      
p = Process.Start(startinfo);
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM