views:

408

answers:

2

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

+4  A: 

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.

Andomar
This worked, but explorer went though the 'Setting up personalized ...' is there a way to tell it not to do this?
Malfist
Nevermind, it only did it the first time
Malfist
+1  A: 

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.

beef2k