我正在尝试通过 VB 运行批处理文件,我需要等待它完成/退出才能继续。我认为我遇到的问题是,当执行批处理文件时,它会打开 cmd.exe 而不是批处理文件。
这是我用VB执行的
My.Computer.FileSystem.DeleteFile(My.Application.Info.DirectoryPath & "\PingCheck\machines.txt")
FileCopy(My.Application.Info.DirectoryPath & "\machines.txt", My.Application.Info.DirectoryPath & "\PingCheck\machines.txt")
Dim psi As New ProcessStartInfo(My.Application.Info.DirectoryPath & "\PingCheck\go.bat")
psi.RedirectStandardError = True
psi.RedirectStandardOutput = True
psi.CreateNoWindow = False
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.UseShellExecute = False
Dim process As Process = process.Start(psi)
process.WaitForExit()
ProgressBar1.Value = ProgressBar1.Value + 2
FileCopy(My.Application.Info.DirectoryPath & "\PingCheck\machines.txt", My.Application.Info.DirectoryPath & "\machines.txt")
'My.Computer.FileSystem.DeleteFile(My.Application.Info.DirectoryPath & "\ping.bat")
MsgBox("Ping Check Complete")
我遇到的问题是它只会在完成之前删除 ping.bat。
如何从我调用的批处理文件中监视进程。然后一旦退出,继续执行脚本?
最佳答案
RHicke 在这里展示了一个如何在 VB.NET 中运行批处理的好例子,Run batch file in vb.net? .
要扩展,您应该使用函数 WaitForExit() 等待进程完成。
Dim psi As New ProcessStartInfo("Path TO Batch File")
psi.RedirectStandardError = True
psi.RedirectStandardOutput = True
psi.CreateNoWindow = False
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.UseShellExecute = False
Dim process As Process = Process.Start(psi)
process.WaitForExit()
关于vb.net - 在继续之前等待批处理文件关闭 - VB.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9095838/