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 Or at least the first part worked, because surprise surprise, windows explorer hadn't reopened 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 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 Explorer turned back on! My program was working
Here's the code:
Code: Select all
#^r:: RunWait taskkill /F /IM explorer.exe Run explorer.exe return