管理 .exe 文件

发布于 2024-08-04 15:01:53 字数 128 浏览 2 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

揽月 2024-08-11 15:01:53

使用 System.IO.File.Exists 和 System.Diagnostics.Process.Start。


        Dim someExe As String = "MyAppsPath\some.exe"
        Dim fullPath As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), someExe)
        If File.Exists(fullPath) Then    'Checks for the existence of the file
            Process.Start(fullPath)      'Executes it
        End If

Use System.IO.File.Exists and System.Diagnostics.Process.Start.


        Dim someExe As String = "MyAppsPath\some.exe"
        Dim fullPath As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), someExe)
        If File.Exists(fullPath) Then    'Checks for the existence of the file
            Process.Start(fullPath)      'Executes it
        End If
终陌 2024-08-11 15:01:53

查看 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.

马蹄踏│碎落叶 2024-08-11 15:01:53

http://msdn.microsoft.com/en-我们/library/system.diagnostics.process.start.aspx

openFileDialog od = new OpenFileDialog();
字符串路径 = od.ToString()
System.Diagnostics.Process.Start(路径)

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx

openFileDialog od = new OpenFileDialog();
string path = od.ToString()
System.Diagnostics.Process.Start(path)

栖迟 2024-08-11 15:01:53

您可以使用 System.Diagnostics.Process 执行 .EXE,如果它是控制台/命令行应用程序,甚至可以捕获输出。
你会得到类似这样的东西(但请记住,这已经被简化了很多!):

dim process as System.Diagnostics.Process
process.StartInfo.FileName = "program.exe"   ' You need to be smarter here!
process.StartInfo.Arguments = "whatever command line options you need"
process.Start()

要检查程序是否仍在运行,你可以调用

process.HasExited()

如果你想捕获输出,你需要将 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!):

dim process as System.Diagnostics.Process
process.StartInfo.FileName = "program.exe"   ' You need to be smarter here!
process.StartInfo.Arguments = "whatever command line options you need"
process.Start()

To check if the program is still running you call

process.HasExited()

If you want to capture the output you need to set StartInfo.RedirectStandardOutput to True.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文