Click here to Skip to main content
15,916,842 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to stop explorer and start again in c++. I can do this from the command line. Is there a way to do this in C++?

C++
FROM THE COMMAND PROMPT
TO STOP explorer
taskkill /F /IM explorer.exe
TO START explorer
explorer


Perhaps system(c:\taskkill / F /IM explorer.exe)

and

system(c:\explorer)
Posted

Using ShellExecute for starting explorer is not recommended. If you do some testing, you might notice that icon overlays and file copying are broken using that method.

The most reliable way is the system command from <stdlib.h>:
C++
system("explorer");

This is the equivalent of Run: explorer or Task Manager->Start New Task: explorer.

I can't believe how many online sources recommend ShellExecute leading to hours of debugging for the developer.
 
Share this answer
 
I would use ShellExecute(); to execute a program! :)

The reason is that i dont like the System(""); function is because it executes other processes to accomplish your programs task and the program "taskkill" may not be avalible on every PC. For example Windows XP Home Edition dont have the "taskkill" program.

C++
#include <windows.h>
ShellExecute(0, 0, "C:\\windows\\system32\\explorer.exe", 0, 0, SW_SHOWDEFAULT);</windows.h>


And with the ShellExecute function, you can specify how the program should be displayed, if you want to hide it or to show it maximized and so on :)
 
Share this answer
 
Comments
Member 7766180 17-Sep-11 21:57pm    
Thank you. That's some useful information!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900