c++ - 如何通过 C++ 启动 explorer.exe?

标签 c++ winapi createprocess

我正在尝试以编程方式启动 explorer.exe,但我没有任何运气。

这是我的代码:

cout << pName << "died, lets restart it." << endl;
STARTUPINFO startupInfo = {0};
startupInfo.cb = sizeof(startupInfo);

PROCESS_INFORMATION processInformation;

if(CreateProcess(pName, NULL, NULL, NULL, false, NORMAL_PRIORITY_CLASS, NULL, NULL, &startupInfo, &processInformation) == 0){
    cout << "Error starting " << pName << ": " << GetLastError() << endl;
}

pName 是 explorer.exe

有人可以告诉我我做错了什么吗?我收到错误代码“2”,即 ERROR_FILE_NOT_FOUND

最佳答案

第一个参数是应用名称;第二个是命令行。尝试将“explorer.exe”指定为第二个参数。

查看此 MSDN article :

lpApplicationName [in, optional]

The name of the module to be executed. This module can be a Windows-based application. It can be some other type of module (for example, MS-DOS or OS/2) if the appropriate subsystem is available on the local computer.

The string can specify the full path and file name of the module to execute or it can specify a partial name. In the case of a partial name, the function uses the current drive and current directory to complete the specification. The function will not use the search path. This parameter must include the file name extension; no default extension is assumed.

关于c++ - 如何通过 C++ 启动 explorer.exe?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/865395/

相关文章:

delphi - 如何将delphi窗体的宽度和高度像素转换为对话框单位?

c++ - GetTickCount() 换行时会发生什么?

使用 PROC_THREAD_ATTRIBUTE_PREFERRED_NODE 或 PROC_THREAD_ATTRIBUTE_GROUP_AFFINITY 时的 CreateProcess 问题

c++ - time_t boost 日期转换给出不正确的结果

C++ 删除队列中的节点

c++ - 如何根据 C++ 标准访问对象表示?

windows - 当我从 CreateProcess 运行 NETSH 时得到 "The system cannot find the file specified"但它在命令提示符下工作正常?

c++ - 静态和动态库链接

multithreading - waveOut (Win32API) 和多线程

c - 将输入发送到在 Windows 计算机上使用 C 中的 createprocess() 创建的进程