-
-
[求助]CreateProcess怎么创建桌面上的EXE进程
-
发表于:
2015-10-31 22:45
3403
-
[求助]CreateProcess怎么创建桌面上的EXE进程
其他地方的都行 比如C盘、文档 里都可以唯独桌面这些地方不行
C++代码如下
TCHAR szBuffer[MAX_PATH] = { 0 };
OPENFILENAME ofn = { 0 };
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.lpstrFilter = _T("Exe文件(*.exe)\0*.exe\0所有文件(*.*)\0*.*\0");//要选择的文件后缀
ofn.lpstrInitialDir = _T("D:\\Program Files");//默认的文件路径
ofn.lpstrFile = szBuffer;//存放文件的缓冲区
ofn.nMaxFile = sizeof(szBuffer) / sizeof(*szBuffer);
ofn.nFilterIndex = 0;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER;//标志如果是多选要加上OFN_ALLOWMULTISELECT
BOOL bSel = GetOpenFileName(&ofn);
//声明必备参数
STARTUPINFO si;
PROCESS_INFORMATION pi;
//将结构中的内存的内容置零 设置结构必备参数
ZeroMemory(&pi, sizeof(pi));
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
if (CreateProcess(szBuffer, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi) == 0)
{
cout << cAppName << endl;
getchar();
return -1;
}
cout << "进程ID:" << pi.dwProcessId << "\n线程ID" << pi.dwThreadId << endl;
getchar();
TerminateProcess(pi.hProcess, NULL);
return 0;
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!