在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
直接上代码吧,有用过CSDN论坛说的WinExec()和system()等方法试过,好像都不太行,另外记得以前shellexec()也可以获取程序返回值的,但是看了下函数好像没有接收返回值的参数,只好用底下这种形式,用WaitForSingleObject()等待程序结束后用GetExitCodeProcess()获取程序返回值 #include "stdafx.h" #include <Windows.h> #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { STARTUPINFOW si; PROCESS_INFORMATION pi; ZeroMemory(&pi, sizeof(pi)); ZeroMemory(&si, sizeof(si)); si.cb = sizeof(STARTUPINFOW); TCHAR cmd[256] = _T("D:\\dev\\YozoUCloud\\setup1.0.3 build437.exe"); BOOL working = ::CreateProcess(NULL, cmd, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi); if (working == 0) { DWORD error = GetLastError(); cout << "CreateProcess Error : " << error << endl; getchar(); return 0; } WaitForSingleObject(pi.hProcess, INFINITE); unsigned long Result; GetExitCodeProcess(pi.hProcess, &Result); cout << "Exit Code : " << Result << endl; getchar(); return 0; }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论