VB.NET读取标准输出

时间:2011-06-30 17:36:11

标签: vb.net

从我的应用程序中,我需要运行一个命令并解析输出。我可以毫无问题地执行此操作,但我不希望显示该命令。我希望WindowStyle = ProcessWindowStyle.Hidden可以工作,但事实并非如此。以下面的示例代码为例。它工作正常,但命令窗口仍然可以快速打开和关闭,我需要它永远不会显示其丑陋的脸。我该如何解决这个问题?

Dim myprocess As New Process
Dim lines As String = ""

With myprocess
    .StartInfo.FileName = "C:\Windows\System32\cmd.exe"
    .StartInfo.Arguments = "/c ipconfig"
    .StartInfo.WindowStyle = ProcessWindowStyle.Hidden
    .StartInfo.RedirectStandardOutput = True
    .StartInfo.UseShellExecute = False
    .Start()
End With

lines = myprocess.StandardOutput.ReadToEnd

MsgBox(lines)

3 个答案:

答案 0 :(得分:4)

尝试将CreateNoWindow设置为True

如果您要实现的目的是找到本地计算机的IP地址,则有more direct ways of doing it

答案 1 :(得分:1)

包含

.StartInfo.CreateNoWindow = True

答案 2 :(得分:0)

串联尝试这些设置:

            .CreateNoWindow = True
            .UseShellExecute = False

有关详细信息,请参阅http://blogs.msdn.com/b/jmstall/archive/2006/09/28/createnowindow.aspx