182

C# を使用してアプリケーションを起動するにはどうすればよいですか?

要件: Windows XPおよびWindows Vistaで動作する必要があります。

Windows Vista でのみ動作する DinnerNow.net サンプラーのサンプルを見たことがあります。

4

9 に答える 9

236

役立つコードの抜粋は次のとおりです。

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

于 2008-10-27T16:55:15.890 に答える
182

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");
于 2008-10-27T14:58:40.480 に答える
62
System.Diagnostics.Process.Start("PathToExe.exe");
于 2008-10-27T14:58:35.767 に答える
21
System.Diagnostics.Process.Start( @"C:\Windows\System32\Notepad.exe" );
于 2009-10-13T06:30:33.100 に答える
16

私のように System.Diagnostics の使用に問題がある場合は、それがなくても機能する次の単純なコードを使用してください。

using System.Diagnostics;

Process notePad = new Process();
notePad.StartInfo.FileName   = "notepad.exe";
notePad.StartInfo.Arguments = "mytextfile.txt";
notePad.Start();
于 2014-06-03T21:23:45.110 に答える
8

さらに、可能であれば、パスに環境変数を使用することをお勧めします: http://en.wikipedia.org/wiki/Environment_variable#Default_Values_on_Microsoft_Windows

例えば

  • %WINDIR% = Windows ディレクトリ
  • %APPDATA% = アプリケーション データ - Vista と XP の間で大きく異なります。

より長いリストについては、リンクをチェックしてください。

于 2008-10-27T16:22:52.947 に答える
5

file.exe を \bin\Debug フォルダーに入れて、次を使用します。

Process.Start("File.exe");
于 2016-04-15T01:33:33.510 に答える
2

Process.Startを使用してプロセスを開始します。

using System.Diagnostics;
class Program
{
    static void Main()
    {
    //
    // your code
    //
    Process.Start("C:\\process.exe");
    }
} 
于 2015-08-27T03:38:43.513 に答える