Paul Accisano
Paul Accisano

Reputation: 1476

What's the cleanest way to programmatically kill and restart explorer.exe?

Greetings all,

I'm working on a Windows program whose installation necessitates restarting explorer.exe. I know "Reboot your computer to complete the installation" is the standard method here, but I'd like my installer to give users the option of just restarting Explorer so they can start using my program immediately. What's the best way to do that? Of course I could just find and kill the process, but that seems rather icky. Is there some trick to, say, make Explorer think the user is logging off and close cleanly?

Thanks!

Upvotes: 3

Views: 3898

Answers (5)

wtjones
wtjones

Reputation: 4160

I use powershell in my post build events like this:

get-process explorer | kill

It generally auto restarts fine

Upvotes: 0

Pier
Pier

Reputation: 11

I don't know if you can implement this, but I downloaded PsTools from:

http://technet.microsoft.com/en-us/sysinternals/bb896649

Then I wrote the following batch file which kills and then executes the explorer.exe process:

pskill explorer.exe
psexec -d explorer.exe
exit

You can also try getting in touch with the author of PSTools Mark Russinovich on the TechNet site.

Upvotes: 1

William Leara
William Leara

Reputation: 10697

Is this an MSI install?

Have you considered using the Restart Manager?

Restart Manager will detect which processes are holding files/handles open and need to be restarted, and allow you to automatically stop/start those processes without a restart.

Upvotes: 2

Nathan Osman
Nathan Osman

Reputation: 73265

You could send it the WM_ENDSESSION message.

That might trick it into thinking the computer is shutting down. Then it will hopefully free all resources, close all open explorer windows, etc.

Then when it is closed, you can restart the process.

Upvotes: 0

compie
compie

Reputation: 10536

I could try to call ExitProcess or TerminateProcess to stop explorer.exe.

Upvotes: 1

Related Questions