运行在.NET和C++中的进程

问题描述:

我搜索按路径运行程序的功能,主程序停止运行直到运行第二程序。我可以通过使用System.Diagnostics.Process类来实现吗?运行在.NET和C++中的进程

+0

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

看看这个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