不隐藏命令窗口无法运行批处理文件

时间:2013-12-24 11:36:02

标签: vb.net

   Dim pi As New System.Diagnostics.ProcessStartInfo()
   pi.FileName=(ipchangepath)
   pi.WorkingDirectory=""
   pi.Verb = "RunAs"
   pi.CreateNoWindow = true
   pi.UseShellExecute = False
   Dim p As process=Process.Start(pi) 
   p.WaitForExit

我正在尝试运行批处理文件,将我的IP地址设置为静态值。但是我不能在不隐藏命令窗口的情况下运行该过程,因为如果ShellExecute不为真,程序将无法运行,如果为真,Window将不会隐藏。

任何帮助?

netsh interface ip set address name=Wi-Fi source=static addr=10.10.118.161 mask=255.255.254.0 gateway=10.10.116.25 gwmetric=0
netsh interface ip set dns "Wi-Fi" static 10.10.116.5
netsh interface ip add dns "Wi-Fi" 202.200.100.95 index=2

批处理文件

3 个答案:

答案 0 :(得分:1)

试试这个答案: Hide Command prompt

或使用此代码:

Dim process As new Process()
process.StartInfo.CreateNoWindow = true
process.StartInfo.RedirectStandardOutput = true
process.StartInfo.UseShellExecute = false
process.StartInfo.FileName = "(ipchangepath)"
process.Start()

答案 1 :(得分:0)

这两行将起到作用

process.StartInfo.CreateNoWindow = true
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden

答案 2 :(得分:-1)

Dim process As new Process()
process.StartInfo.CreateNoWindow = true
process.StartInfo.RedirectStandardOutput = true
process.StartInfo.UseShellExecute = false
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
process.StartInfo.FileName = "(ipchangepath)"
process.Start()