通過輸入程式位置啟動可執行(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
更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/cplus/