1

I'd like to restart Explorer when building my DLL in Visual Studio. I've tried adding taskkill /f /IM explorer.exe and start explorer as pre-build events in the project configuration. When I then build my project, Explorer will in fact be terminated, but it will not be successfully restarted. The taskbar will remain missing. Only after starting explorer from a command prompt will it return. I've also tried executing a call to those commands in a .bat file, but I get the same problem (although the .bat file works properly when executed on its own, outside Visual Studio). I've also tried putting the relaunch part in a post-build event, but no dice. Is there any trick to getting Explorer to relaunch successfully in a pre-build event? Thanks for any input.

  • `Start` is an internal command in `cmd.exe`, so, as you've already stated that it works from the Command Prompt, _(`cmd.exe`)_, does `Cmd /C Start Explorer` not work? Or just `Explorer` on its own? – Compo Nov 17 '19 at 16:57
  • No, unless I'm doing something wrong, those don't seem to work either. –  Nov 17 '19 at 17:08

1 Answers1

0

You can restart Explorer by putting the following commands into a Batch file:

@echo off
taskkill /f /im explorer.exe
start explorer.exe
exit

(The /f switch will force the termination of Explorer.)

Then, you can execute that Batch file as a pre-build step (Build Events → Pre-Build Event → Command Line).

If this is a necessary part of your build process, I would recommend adding this Batch file to your solution directory, committing it to your version-control system, and using a relative path in your solution properties.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574