-
-
[求助]CreateProcess怎么创建桌面上的EXE进程
-
发表于:
2015-10-31 22:45
3404
-
[求助]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;
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课