这是一个有用代码片段:
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,Process。
使用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");
System.Diagnostics.Process.Start("PathToExe.exe");
System.Diagnostics.Process.Start( @"C:\Windows\System32\Notepad.exe" );
如果你像我一样使用 System.Diagnostics 时遇到问题,可以使用以下简单的代码,而无需使用它:
using System.Diagnostics;
Process notePad = new Process();
notePad.StartInfo.FileName = "notepad.exe";
notePad.StartInfo.Arguments = "mytextfile.txt";
notePad.Start();
Process
在 System.Diagnostics
中。 - Paul Sinclair只需将您的 file.exe 文件放入 \bin\Debug 文件夹中,然后使用以下命令:
Process.Start("File.exe");
using System.Diagnostics;
class Program
{
static void Main()
{
//
// your code
//
Process.Start("C:\\process.exe");
}
}
试试这个:
Process.Start("Location Of File.exe");
请确保使用 System.Diagnostics 库。
System.Diagnostics.Process.Start(@"C:\Users\Blank\Desktop\PdfFile.pdf");
- DLehPathTo*.exe
,但我不会期望它能正常工作。(a) 如果有多个匹配项怎么办?(b) 我希望微软的代码不会允许这样做,因为这会造成弱安全性。 - sfuqua