【问题标题】:hide cmd in vb.net not working在 vb.net 中隐藏 cmd 不起作用
【发布时间】:2017-03-26 06:33:33
【问题描述】:

我试图用 vb.net 隐藏 cmd 窗口,但没有成功。

Dim oProcess As New Process()
Dim oStartInfo As New ProcessStartInfo("cmd.exe", " /c cscript ""%windir%\system32\slmgr.vbs"" /xpr | findstr ""The machine""")
oStartInfo.WindowStyle = ProcessWindowStyle.Minimized
oStartInfo.WindowStyle = ProcessWindowStyle.Hidden

oStartInfo.UseShellExecute = False
oStartInfo.RedirectStandardOutput = True
oProcess.StartInfo = oStartInfo
oProcess.Start()

Dim sOutput As String
Using oStreamReader As System.IO.StreamReader = oProcess.StandardOutput
    sOutput = oStreamReader.ReadToEnd()

End Using
TextBox4.Text = sOutput

请帮助我的代码中的错误是什么?

【问题讨论】:

标签: vb.net shell command-line cmd hidden


【解决方案1】:

您还必须设置CreateNoWindow property

oStartInfo.CreateNoWindow = True

另外,这只是多余的:

oStartInfo.WindowStyle = ProcessWindowStyle.Minimized '<-- Remove this line.
oStartInfo.WindowStyle = ProcessWindowStyle.Hidden

WindowStyle 设置为最小化不会影响任何事情,因为之后您将其更改为Hidden。当您使用 = 运算符时,您替换变量或属性的当前值为新值。

【讨论】:

  • 很高兴我能帮上忙!祝你好运! :)
猜你喜欢
  • 2010-11-20
  • 2016-02-02
  • 1970-01-01
  • 2015-03-10
  • 2013-07-12
  • 2016-04-19
  • 2017-03-28
  • 1970-01-01
相关资源
最近更新 更多