Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I start explorer.exe via C++?

I'm trying to programmatically start explorer.exe but I'm not having any luck.

This is my code:

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;
}

and pName is explorer.exe

Can someone tell me what I'm doing wrong? I get the error code '2' which is ERROR_FILE_NOT_FOUND

like image 646
Malfist Avatar asked May 14 '09 20:05

Malfist


People also ask

How do I start explorer.exe from command prompt?

You can also open File Explorer from CMD, just as you can also open Windows Explorer from CMD. If you like working with Windows Terminal, Command Prompt, or PowerShell, type the command explorer in any of them and press Enter.

What is C EXE Windows Explorer?

Explorer.exe is an executable in the Windows operating systems that is located at C:\Windows\explorer.exe. When Windows starts and a user logs in, the operating system will launch the Explorer.exe process, which displays the Windows user environment such as the desktop, taskbar, and Start Menu.

How do I start Windows Explorer program?

To launch File Explorer this way, press Ctrl+Shift+Esc to open Task Manager. Then, click “File” and select “Run New Task.” The “Create New Task” window will appear. Type “Explorer” in the “Open:” text box, click “OK,” and File Explorer will open.

How do I open C drive in File Explorer?

Broadly the same as previous versions of Windows, click on file explorer, click on This PC, you'll find the C drive there. Was this reply helpful? Hi XYZ, If you click start, and type “this pc” and open it up, you should see your C drive right there.


2 Answers

The first parameter is the application name; the second is the command line. Try specifying "explorer.exe" as the second parameter.

See this 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.

like image 107
Andomar Avatar answered Sep 24 '22 23:09

Andomar


You probably should give "ShellExecuteEx" a try. This function lets you specify a file or folder and a verb that describes what to do with it. If you use "explore" as the verb, it will open Windows Explorer with the given folder.

like image 36
beef2k Avatar answered Sep 24 '22 23:09

beef2k