vb.net - 在继续之前等待批处理文件关闭 - VB.net

标签 vb.net

我正在尝试通过 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/

相关文章:

vb.net - 从子实例调用被覆盖的基类方法

mysql - SQL 一次查询两个表并将结果作为 JSON 对象循环

vb.net - 始终处于领先地位的桌面 YouTube 播放器

c# - 如何更改按下键盘按键时的 TrackBar 控件操作?

c# - 确保在 Visual Studio 中为 Windows Phone 正确设置引用

asp.net - 从字符串 "31/03/2012"到类型 'Date' 的转换无效

vb.net 数据集返回空值

vb.net - 将整数拆分为数组VB

mysql - 从 VB 程序向数据库添加数据 -> 安全方式?

c# - 命名空间 System.Windows.Automation 的用途是什么