首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >从C#启动应用程序(.EXE)?

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

Stack Overflow用户
提问于 2008-10-27 14:55:38
回答 7查看 400.6K关注 0票数 182

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

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

我已经看过一个来自DinnerNow.net采样器的样本,它只能在Windows和Vista中工作。

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2008-10-27 14:58:40

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

请查看this article了解如何使用它。

代码语言:javascript
复制
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");
票数 182
EN

Stack Overflow用户

发布于 2008-10-27 16:55:16

下面是一些有用的代码片段:

代码语言:javascript
复制
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;
}

你可以用这些对象做更多的事情,你应该阅读文档:ProcessStartInfoProcess

票数 236
EN

Stack Overflow用户

发布于 2008-10-27 14:58:36

代码语言:javascript
复制
System.Diagnostics.Process.Start("PathToExe.exe");
票数 62
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/240171

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档