Unable to restart Windows Explorer with AHK

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
gx240
Posts: 20
Joined: 11 Jul 2017, 03:03

Unable to restart Windows Explorer with AHK

02 Oct 2023, 14:03

Code: Select all

$f4::
sleep 5000
run taskkill /F /IM explorer.exe 
sleep 5000
run explorer.exe     ;;;;; This doesn't work. It only opens a "This PC" window.
return
On Windows 10 if you kill explorer.exe the Start menu, taskbar, and desktop all disappear leaving nothing but a black screen. You can then start explorer.exe again from the Task Manager to bring everything back.

Starting explorer from an AHK script doesn't seem to work though. When I use "run explorer.exe" in an AHK script it just opens a window showing "This PC." It doesn't bring back the whole Windows Explorer UI (the Start menu, taskbar, desktop, etc). It looks like this:
2.png
2.png (93.33 KiB) Viewed 864 times

But if I open the Task Manager and run "explorer" from the "Create new task" window, then explorer.exe runs correctly and the Start menu, taskbar, and desktop return.
1.png
1.png (53.69 KiB) Viewed 864 times

Why does running the same command lead to different outcomes in an AHK script and the "Create new task" window?
GEV
Posts: 1005
Joined: 25 Feb 2014, 00:50

Re: Unable to restart Windows Explorer with AHK

03 Oct 2023, 01:53

Try this

Code: Select all

$f4::
	RunWait, %comspec% /c taskkill /f /im explorer.exe ,,hide
	Process, WaitClose, explorer.exe
	; sleep 500
	Run, explorer.exe
return
gx240
Posts: 20
Joined: 11 Jul 2017, 03:03

Re: Unable to restart Windows Explorer with AHK

12 Oct 2023, 23:10

Unfortunately that does the same thing. It just opens a "This PC" window instead of restarting the whole explorer.exe with the Start menu, taskbar, and desktop. I've also tried running the script as both admin and non-admin.

I'm just confused as to why the run command is producing different results when it comes from an AHK script.
User avatar
lmstearn
Posts: 698
Joined: 11 Aug 2016, 02:32
Contact:

Re: Unable to restart Windows Explorer with AHK

13 Oct 2023, 00:04

There is a script SKAN posted a while back - any help? Edit: Oops, doesn't relaunch explorer (W10) as is the problem here, sorry, perhaps the more forceful method malcev posted there works instead?
Another way is to use the Restart Manager API, where you could use the C++ functions in this SO answer, doing so might require some investment in time, however.
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH
GEV
Posts: 1005
Joined: 25 Feb 2014, 00:50

Re: Unable to restart Windows Explorer with AHK

13 Oct 2023, 06:08

You can also try this VBScript:

Code: Select all

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") 
Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'explorer.exe'")
For Each objProcess in colProcess
  objProcess.Terminate()
Next
Set objProcess = objWMIService.Get("Win32_Process")
intreturn = objProcess.Create ("explorer.exe","",SW_NORMAL)

Save the file as Restart Explorer.vbs
User avatar
V0RT3X
Posts: 248
Joined: 20 May 2023, 21:59
Contact:

Re: Unable to restart Windows Explorer with AHK

13 Oct 2023, 08:26

@gx240, I don't know that this will do you any better, but it works for me on 64-bit Windows 10. But then again, @GEV's works for me also.

viewtopic.php?t=91600
jrachr
Posts: 545
Joined: 01 Mar 2021, 17:33

Re: Unable to restart Windows Explorer with AHK

13 Oct 2023, 10:13

Try this.Scroll to the bottom.Works for me.

viewtopic.php?f=76&t=122098

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: fiaztv1, Pianist and 172 guests