2010-03-16 67 views
0

我搜索按路徑運行程序的功能,主程序停止運行直到運行第二程序。我可以通過使用System.Diagnostics.Process類來實現嗎?運行在.NET和C++中的進程

+0

當然可以。希望你不要以爲你可以在C++中使用相同的代碼。 – 2010-03-16 10:30:57

回答

0

看看這個question


使用這個,如果你想只使用Win32 API的

#include <stdio.h> 
#include <Windows.h> 

int main(int argc, char ** argv) 
{ 
STARTUPINFO SI; 
PROCESS_INFORMATION PI; 
memset(&SI,0,sizeof(SI)); 
memset(&PI,0,sizeof(PI)); 
SI.cb = sizeof(SI); 

//ProcessorCap 
if(!CreateProcess(NULL,"Notepad.exe ",NULL,NULL,false,0,NULL,NULL,&SI,&PI)) 
{ 
    printf("Error %d",GetLastError()); 
    return 1; 
} 
DWORD ExitCode; 
do 
{ 
    GetExitCodeProcess(PI.hProcess,&ExitCode); 
    Sleep(100); 
}while (ExitCode == STILL_ACTIVE); 
printf("Exited"); 
} 
+0

我已經寫在C#上的例子什麼工作正確 ProcessStartInfo info = new ProcessStartInfo(); info.FileName =「C:\\ ACD.exe」; Process process = Process.Start(info); process.WaitForExit(); 但當我寫在c + +我有錯誤,因爲我的進程沒有關聯的過程 – Xaver 2010-03-16 09:15:10