C #에서 응용 프로그램 (.EXE)을 시작 하시겠습니까? 사용하여 응용

C #을 사용하여 응용 프로그램을 시작하려면 어떻게해야합니까?

요구 사항 : Windows XPWindows Vista 에서 작동해야합니다 .

DinnerNow.net 샘플러에서 Windows Vista에서만 작동하는 샘플을 보았습니다.



답변

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");

답변

다음은 유용한 코드 스 니펫입니다.

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("PathToExe.exe");

답변

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

답변

내가했던 것처럼 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

EG

  • % WINDIR % = Windows 디렉토리
  • % APPDATA % = 응용 프로그램 데이터-Vista와 XP에 따라 다릅니다.

더 긴 목록을 보려면 더 많은 링크를 확인하십시오.


답변

file.exe를 \ bin \ Debug 폴더에 넣고 다음을 사용하십시오.

Process.Start("File.exe");