如何从C#代码中打开一个exe [英] How to open an exe from C# code

查看:99
本文介绍了如何从C#代码中打开一个exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从按钮点击打开一个.exe文件。



这是我的代码:



I want to open an .exe file from button click.

Here is my code:

Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = false;
myProcess.Start();
StartInfo.FileName = @"C:\Users\MyName\Desktop\NewFolder\Application.exe";





这不行。

任何人都可以告诉我什么是错的。



我尝试了什么:



创建了一个应用程序,用于从按钮单击事件中打开可执行文件。



This is not working.
Can anyone please tell me whats wrong.

What I have tried:

Created an application to open an executable file from button click event.

推荐答案

你的命令顺序错误,也忘了最后一个变量名声明。

You have the wrong order of things and also forgot the variable name in the last statement.
Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = false;
myProcess.Start();
StartInfo.FileName = @"C:\Users\MyName\Desktop\NewFolder\Application.exe";



应该是


should be

Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.FileName = @"C:\Users\MyName\Desktop\NewFolder\Application.exe";
myProcess.Start();


试试



try

ProcessStartInfo startInfo = new ProcessStartInfo (@"C:\Users\MyName\Desktop\NewFolder\Application.exe");
           startInfo.UseShellExecute =false;
           Process.Start(startInfo);








or

ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\Users\MyName\Desktop\NewFolder\Application.exe");
Process myProcess = new Process();
myProcess.StartInfo = startInfo;
myProcess.Start();


没有打开EXE这样的概念。您可以打开.EXE文件并读取其字节,然后将其关闭。我怀疑这是你想要的(但我可以解释如何去做,只要你解释这样做的目的:-))。或者您可以简单地使用该文件(可能是给定平台的有效应用程序文件)来启动该应用程序。具体方法如下: Process.Start方法(系统) .Diagnostics) [ ^ ]。



-SA
There is no such concept as "open an EXE". You can open a ".EXE" file file and read its bytes, then close it. I doubt that this is what you want (but I could explain how to do it, only if you explain the purpose of doing so :-)). Or you can simply use the file, which might be the valid application file for the given platform, to start that application. This is how: Process.Start Method (System.Diagnostics)[^].

—SA


这篇关于如何从C#代码中打开一个exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆