Restart Windows Explorer (or any other process) with taskkill

Put simple Tips and Tricks that are not entire Tutorials in this forum
The-Anonymous
Posts: 4
Joined: 13 Jun 2021, 04:33
Contact:

Restart Windows Explorer (or any other process) with taskkill

Post by The-Anonymous » 13 Jun 2021, 07:00

Users are frequently switched on my Windows 10 PC, and you'll be surprised to know how many bugs arise because of user-switching. Every time I came back to my PC and switched back to my user, countless bugs awaited me. Before I realized I could go to the Task Manager, find Windows Explorer in the list, right click it and click restart to fix every single bug, I used to reboot my PC. But even that is a tedious process. So I tried creating a script which could restart Explorer for me automatically.

I was still a beginner to AHK, so I searched online for a solution. I got one result that restarted an app - not just Windows Explorer, any app - using AHK, but guess what - it was more than ten years old, and the code was really long and complicated anyway.
But there were more results that weren't related to AHK at all - and one of them used the taskkill command in Command Prompt to stop Explorer. And I tried it myself - it worked. So I simply copied the command to an AHK script, added "Run explorer.exe" on the next line, and... It worked :dance: Or at least the first part worked, because surprise surprise, windows explorer hadn't reopened :x Luckily, I hadn't closed Command Prompt after testing the command, so I just typed "explorer.exe" to reopen explorer.
After going through the AHK docs, I finally found the RunWait command, which runs something, and then waits until it has closed. But at the time, I thought it waited until a specific program was closed. So, I slapped "RunWait explorer.exe" after the taskkill command, and... It didn't work. It took me a ton of time to realize that I had misunderstood what the RunWait command did - it didn't just wait till something was closed, it ran that thing and then waited until it was closed :wtf: So, I got rid of the RunWait line, and added a RunWait before the taskkill command.
I nervously pressed the hotkey on my keyboard. As expected, Windows Explorer was killed - and now for the moment of truth :shh: Explorer turned back on! My program was working :superhappy:

Here's the code:

Code: Select all

#^r::
RunWait taskkill /F /IM explorer.exe 
Run explorer.exe
return

Return to “Tips and Tricks (v1)”