vb.net 单击按钮 --> 启动 *.exe 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2631223/
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
Click a button --> Launch a *.exe file
提问by Computeristic
Basically, what I want to do is launch an *.exe file when I click on a button. I want this done in VB.NET. I have Microsoft Visual Basic 2008 Express Edition.
基本上,我想做的是在单击按钮时启动一个 *.exe 文件。我希望这在 VB.NET 中完成。我有 Microsoft Visual Basic 2008 Express Edition。
The button I have is called 'btnYES'.
我的按钮叫做“btnYES”。
How can I launch an *.exe file from the click of this button?
如何通过单击此按钮启动 *.exe 文件?
回答by Dirk Vollmar
In the event handler of the button call
在按钮调用的事件处理程序中
Process.Start("C:\path_to\myapp.exe")
You will find further samples in the MSDN documentation for Process.Start()
.
您将在 MSDN 文档中找到更多示例Process.Start()
。
In case you don't know how an event handler is created: Simply open the form in the designer and double-click on the btnYes
button. This will automatically create an event handler for the button click event and the IDE will open the code file for you at the correct position.
如果您不知道如何创建事件处理程序:只需在设计器中打开表单并双击btnYes
按钮即可。这将自动为按钮单击事件创建一个事件处理程序,IDE 将在正确的位置为您打开代码文件。
回答by ezzsakr
If you want to call an exe file by code:
如果你想通过代码调用一个exe文件:
If the file is a single file do the following:
Process.Start("D:\MATI2\MATI.EXE")
如果文件是单个文件,请执行以下操作:
Process.Start("D:\MATI2\MATI.EXE")
You can obtain the path by right click the exe file while pressing shift and choosing copy as path
您可以通过右键单击exe文件并按住shift键并选择复制作为路径来获取路径
If the file is dependent on one or more .dll files the previous way will not work, use the following:
Dim info As New ProcessStartInfo() info.FileName = "C:\Program Files (x86)\VentSrv\ventrilo_srv.exe" info.WorkingDirectory = "C:\Program Files (x86)\VentSrv" info.Arguments = "<specify the command line arguments here if necessary>" Process.Start(info)
如果文件依赖于一个或多个 .dll 文件,以前的方法不起作用,请使用以下方法:
Dim info As New ProcessStartInfo() info.FileName = "C:\Program Files (x86)\VentSrv\ventrilo_srv.exe" info.WorkingDirectory = "C:\Program Files (x86)\VentSrv" info.Arguments = "<specify the command line arguments here if necessary>" Process.Start(info)