通過輸入程序位置啟動可執行(exe)程序, 使用windows的CreateProcess()函數, 即可.
示例是調用預先生產的可執行(exe)程序.
代碼:
/* * main.cpp * * Created on: 2014.06.08 * Author: Spike */ /*vs 2012*/ #include <iostream> #include <windows.h> using namespace std; bool startProcess (const std::string name_) { STARTUPINFO si; //參數設置 memset(&si, 0, sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_SHOW; PROCESS_INFORMATION pi; //參數結束 /*printf("Please enter the name of process to start:"); std::string name; cin >> name;*/ if (!CreateProcess(NULL, (LPSTR)name_.c_str(), NULL, NULL, FALSE, 0,NULL,NULL,&si,&pi)) { cout<<"Create Error!"<<endl; return false; } else { cout<<"Create Sucess!"<<endl; } return true; } int main() { const std::string name = "D:/Test/Image.exe"; if (!startProcess(name)) { cout << "Start Process Error!" << endl; } return 0; }
注: Image.exe 是預先生產的可執行(exe)程序.
作者:csdn博客 Spike_King