在 vb.net 中隐藏 cmd 不工作
hide cmd in vb.net not working
我试图用 vb.net 隐藏 cmd windows 但没有成功。
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
任何帮助,我的代码中有什么错误?
您还必须设置 CreateNoWindow
property。
oStartInfo.CreateNoWindow = True
此外,这只是多余的:
oStartInfo.WindowStyle = ProcessWindowStyle.Minimized '<-- Remove this line.
oStartInfo.WindowStyle = ProcessWindowStyle.Hidden
将 WindowStyle
设置为最小化不会影响任何事情,因为您随后将其更改为 Hidden
。当您使用 =
运算符时,您 将 变量或 属性 的当前值替换为新值。
我试图用 vb.net 隐藏 cmd windows 但没有成功。
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
任何帮助,我的代码中有什么错误?
您还必须设置 CreateNoWindow
property。
oStartInfo.CreateNoWindow = True
此外,这只是多余的:
oStartInfo.WindowStyle = ProcessWindowStyle.Minimized '<-- Remove this line.
oStartInfo.WindowStyle = ProcessWindowStyle.Hidden
将 WindowStyle
设置为最小化不会影响任何事情,因为您随后将其更改为 Hidden
。当您使用 =
运算符时,您 将 变量或 属性 的当前值替换为新值。