您的位置:首页 > 编程语言 > C语言/C++

Windows编程 - 启动可执行(exe)程序 代码(C++)

2014-06-08 18:06 465 查看

启动可执行(exe)程序 代码(C++)

本文地址: http://blog.csdn.net/caroline_wendy

通过输入程序位置启动可执行(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)程序.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐