从 C # 启动应用程序(. EXE) ?

如何使用 C # 启动应用程序?

要求: 必须在 视窗 XPWindows Vista上工作。

我看过一个来自 DinnerNow.net 采样器的示例,它只能在 Windows Vista 中使用。

418353 次浏览
System.Diagnostics.Process.Start("PathToExe.exe");

使用 System.Diagnostics.Process.Start()方法。

查看 这篇文章的使用方法。

Process.Start("notepad", "readme.txt");


string winpath = Environment.GetEnvironmentVariable("windir");
string path = System.IO.Path.GetDirectoryName(
System.Windows.Forms.Application.ExecutablePath);


Process.Start(winpath + @"\Microsoft.NET\Framework\v1.0.3705\Installutil.exe",
path + "\\MyService.exe");

此外,如果可能的话,您还需要为您的路径使用环境变量: http://en.wikipedia.org/wiki/Environment_variable#Default_Values_on_Microsoft_Windows

脑电图。

  • % WINDIR% = Windows 目录
  • % APPDATA% = 应用程序数据 - Vista 和 XP 之间差别很大。

还有更多的链接可以查看更长的列表。

下面是一段有用的代码:

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;
}

您可以对这些对象做更多的事情,您应该阅读文档: ProcessStartInfo过程

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

如果您在使用 System.Diagnostics 时遇到了像我这样的问题,可以使用以下简单的代码,这些代码可以在不使用 System.Diagnostics 的情况下工作:

using System.Diagnostics;


Process notePad = new Process();
notePad.StartInfo.FileName   = "notepad.exe";
notePad.StartInfo.Arguments = "mytextfile.txt";
notePad.Start();

使用 过程,开始启动进程。

using System.Diagnostics;
class Program
{
static void Main()
{
//
// your code
//
Process.Start("C:\\process.exe");
}
}

只需将 file.exe 放入 bin Debug 文件夹并使用:

Process.Start("File.exe");

试试这个:

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

(请确保使用 System.Diagnostics 库)