在 vb.net 中运行批处理文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2178872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:38:38  来源:igfitidea点击:

Run batch file in vb.net?

vb.net

提问by Alex

How can I run a batch from from within vb.net?

如何从 vb.net 中运行批处理?

回答by RHicke

You can use the Process class to run a batch file

您可以使用 Process 类来运行批处理文件

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)

回答by Vivek Bernard

Simple and straight forward method

简单直接的方法

System.Diagnostics.Process.Start("c:\batch.bat")

System.Diagnostics.Process.Start("c:\batch.bat")

回答by JaredPar

The best way is to use the Process.Startand pass the path to the batch file

最好的方法是使用Process.Start并将路径传递给批处理文件

Process.Start(pathToBatchFile)

回答by djbaldwin

'The easiest way if you know the exact location of the file is

'如果您知道文件的确切位置,最简单的方法是

System.Diagnostics.Process.Start("c:\test\file.bat")

System.Diagnostics.Process.Start("c:\test\file.bat")

'In Visual Studio the file must exist in the /bin/debug or /bin/release depending on your current build configuration

'在 Visual Studio 中,该文件必须存在于 /bin/debug 或 /bin/release 中,具体取决于您当前的构建配置

System.Diagnostics.Process.Start("test.bat")

System.Diagnostics.Process.Start("test.bat")