#include <windows.h> int main() { STARTUPINFO mStatusInfo; memset(&mStatusInfo, 0, sizeof(STARTUPINFO)); mStatusInfo.cb = sizeof(mStatusInfo); PROCESS_INFORMATION mProcessInfor; CreateProcess(NULL,"SSOService /service", NULL, NULL, 0, 0, NULL, NULL, &mStatusInfo, &mProcessInfor); //用下面地代码等待程序执行结束: WaitForSingleObject(mProcessInfor.hProcess, INFINITE); CreateProcess(NULL,"net start SSOService", NULL, NULL, 0, 0, NULL, NULL, &mStatusInfo, &mProcessInfor); WaitForSingleObject(mProcessInfor.hProcess, INFINITE); return 0; }
其会按照顺序,从上到下执行语句,等上面的内容执行完成后,再执行下面的调用。