2008-10-27 5 views

답변

50
System.Diagnostics.Process.Start("PathToExe.exe"); 
+0

exe의 전체 이름을 모르는 경우 "PathTo * .exe"를 호출하려고합니다. 이것이 가능합니까? – vishal

8

또한 당신은 가능한 모든 경우에 당신의 경로에 대한 환경 변수를 사용하는 것이 좋습니다

  • %의 WINDIR %의 = 윈도우 디렉토리
  • %의 APPDATA의 % = 응용 프로그램 데이터 - 비스타와 XP 사이에 많이 달라집니다.

긴 목록에 대한 링크가 더 많습니다. ProcessStartInfo, Process : 훨씬 더 이러한 개체로 할 수있다

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; 
} 

, 당신은 문서를 읽어야

196

여기에 도움이 코드의 조각입니다.

+6

그냥 .exes 이외의 다른 파일 형식에서도 작동하는 것 같습니다. 열려고하는 파일을 가리키면 열리면 Windows가 열 것입니다. System.Diagnostics.Process.Start (@ "C : \ Users \ Blank \ Desktop \ PdfFile.pdf"); – DLeh

+0

WindowStyle = ProcessWindowStyle.Hidden은 비 GUI 용입니다.처음 실행했을 때 UseShellExecute = false없이 실패했지만 지금은 작동합니다. 거기에 무슨 일이 일어나고 있는지 확실하지 않습니다 ... – Barton

+0

진실로, 나는 GUI 애플 리케이션으로 이것을 시도한 적이 없다. – sfuqua

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

당신이 내가 가진처럼, 그것없이 작동합니다 다음과 같은 간단한 코드를 사용 System.Diagnostics 네임을 사용하는 데 문제가있는 경우 : 프로세스를 시작

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

"System.Diagonostics가없는"이 기능은 무엇입니까? '프로세스 '는 System.Diagnostics에 있습니다. –

0

사용 Process.Start를합니다.

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

는 그냥 \ 빈 \ Debug 폴더에 file.exe가 넣어 사용하십시오

Process.Start("File.exe"); 
+0

당신의 대답은 이전의 것들 모두에서 어떻게 개선됩니까? – mustaccio

1

을이 :

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

(당신이 열고 System.Diagnostics 라이브러리를 사용하는지 확인)

-1

아담 케인

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

위대한 작품 !!!!!

관련 문제