C# を使用してアプリケーションを起動するにはどうすればよいですか?
要件: Windows XPおよびWindows Vistaで動作する必要があります。
Windows Vista でのみ動作する DinnerNow.net サンプラーのサンプルを見たことがあります。
C# を使用してアプリケーションを起動するにはどうすればよいですか?
要件: Windows XPおよびWindows Vistaで動作する必要があります。
Windows Vista でのみ動作する DinnerNow.net サンプラーのサンプルを見たことがあります。
役立つコードの抜粋は次のとおりです。
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();
さらに、可能であれば、パスに環境変数を使用することをお勧めします: http://en.wikipedia.org/wiki/Environment_variable#Default_Values_on_Microsoft_Windows
例えば
より長いリストについては、リンクをチェックしてください。
file.exe を \bin\Debug フォルダーに入れて、次を使用します。
Process.Start("File.exe");
Process.Startを使用してプロセスを開始します。
using System.Diagnostics;
class Program
{
static void Main()
{
//
// your code
//
Process.Start("C:\\process.exe");
}
}