首页 文章

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

提问于
浏览
141

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

要求:必须适用于Windows XPWindows Vista .

我见过来自DinnerNow.net采样器的样本,该样本仅适用于Windows Vista .

10 回答

  • 150

    试试这个:

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

    (确保使用System.Diagnostics库)

  • 8

    只需将您的file.exe放在\ bin \ Debug文件夹中,然后使用:

    Process.Start("File.exe");
    
  • 211

    凯恩

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

    这很棒!!!!!

  • 13
    System.Diagnostics.Process.Start("PathToExe.exe");
    
  • 0
    System.Diagnostics.Process.Start( @"C:\Windows\System32\Notepad.exe" );
    
  • 1

    使用 Process.Start 启动进程 .

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

    此外,如果可能的话,您将希望使用环境变量:http://en.wikipedia.org/wiki/Environment_variable#Default_Values_on_Microsoft_Windows

    例如 .

    • %WINDIR%= Windows目录

    • %APPDATA%=应用程序数据 - 在Vista和XP之间变化很大 .

    还有更多查看链接以获取更长的列表 .

  • 4

    如果您在使用System.Diagnostics时遇到问题,请使用以下简单代码,无需使用它:

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

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

    查看this article如何使用它 .

  • 18

    这是一段有用的代码:

    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 .

相关问题