Launching an application (.EXE) from C#?

2019-01-01 03:17发布

How can I launch an application using C#?

Requirements: Must work on Windows XP and Windows Vista.

I have seen a sample from DinnerNow.net sampler that only works in Windows Vista.

10条回答
临风纵饮
2楼-- · 2019-01-01 03:51

Just put your file.exe in the \bin\Debug folder and use:

Process.Start("File.exe");
查看更多
倾城一夜雪
3楼-- · 2019-01-01 03:55

Adame Kane

System.Diagnostics.Process.Start(@"C:\Windows\System32\Notepad.exe");

this worked great!!!!!

查看更多
裙下三千臣
4楼-- · 2019-01-01 03:59

Try this:

Process.Start("Location Of File.exe");

(Make sure you use the System.Diagnostics library)

查看更多
倾城一夜雪
5楼-- · 2019-01-01 04:02

Use System.Diagnostics.Process.Start() method.

Check out this article on how to use it.

查看更多
有味是清欢
6楼-- · 2019-01-01 04:02

Here's a snippet of helpful code:

using System.Diagnostics;

// Prepare the process to run
ProcessStartInfo start = new ProcessStartInfo();
// Enter in the command line arguments, everything you would enter after the executable name itself
start.Arguments = arguments; 
// Enter the executable to run, including the complete path
start.FileName = ExeName;
// Do you want to show a console window?
start.WindowStyle = ProcessWindowStyle.Hidden;
start.CreateNoWindow = true;
int exitCode;


// Run the external process & wait for it to finish
using (Process proc = Process.Start(start))
{
     proc.WaitForExit();

     // Retrieve the app's exit code
     exitCode = proc.ExitCode;
}

There is much more you can do with these objects, you should read the documentation: ProcessStartInfo, Process.

查看更多
无色无味的生活
7楼-- · 2019-01-01 04:03

Additionally you will want to use the Environment Variables for your paths if at all possible: http://en.wikipedia.org/wiki/Environment_variable#Default_Values_on_Microsoft_Windows

E.G.

  • %WINDIR% = Windows Directory
  • %APPDATA% = Application Data - Varies alot between Vista and XP.

There are many more check out the link for a longer list.

查看更多
登录 后发表回答