管理 .exe 文件
在 VB.net 中,如何以编程方式启动 .exe 文件?有没有办法检查文件是否存在?
我知道有一些方法可以使用 System.IO 进行检查,但我不知道。但是,我什至不知道如何启动该 .exe(如果存在),所以感谢您的帮助!
In VB.net, how can you programmatically launch a .exe file? Is there a way to check if the file is there?
I know there is some way to check using System.IO, but I have no idea. However, I have not even the slightest clue as to how to launch that .exe if it is there, so thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 System.IO.File.Exists 和 System.Diagnostics.Process.Start。
Use System.IO.File.Exists and System.Diagnostics.Process.Start.
查看 System.Diagnostics.Process 类。 MSDN页面上有一个完美的代码片段,所以我不会在这里重复它。
Process 的巧妙之处在于您实际上可以启动一个文件(例如 HTML 文件),并且它将使用用户的默认浏览器打开。许多常见程序也接受命令行参数 - 许多浏览器接受 URL 作为命令行参数,以便您可以打开特定的 URL。
Check out the System.Diagnostics.Process class. There's a perfect code snippet on the MSDN page, so I won't duplicate it here.
The neat thing about Process is that you can actually launch a file (say, an HTML file) and it will open using the user's default browser. Many common programs accept command-line parameters as well - many browsers accept a URL as a command-line parameter so you can open a specific URL.
http://msdn.microsoft.com/en-我们/library/system.diagnostics.process.start.aspx
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx
您可以使用 System.Diagnostics.Process 执行 .EXE,如果它是控制台/命令行应用程序,甚至可以捕获输出。
你会得到类似这样的东西(但请记住,这已经被简化了很多!):
要检查程序是否仍在运行,你可以调用
如果你想捕获输出,你需要将 StartInfo.RedirectStandardOutput 设置为 True。
You can use System.Diagnostics.Process to execute an .EXE, and can even capture the output if it is a console / command-line application.
You would have something like this (but bear in mind this is simplified quite a bit!):
To check if the program is still running you call
If you want to capture the output you need to set StartInfo.RedirectStandardOutput to True.