Pop "Safely Remove Hardware" menu from Win10 tray

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
mrdev
Posts: 5
Joined: 11 Feb 2018, 13:54

Pop "Safely Remove Hardware" menu from Win10 tray

11 Feb 2018, 14:35

Hello,

I "lifted" the following piece of code from the archived board:
https://autohotkey.com/board/topic/3773 ... /?p=237440
Thanks to pajenn and SKAN for it (hope I got this right).

Code: Select all

SafelyRemoveHardware() {
  if WinExist("Battery Meter") and WinExist("ahk_class SystemTray_Main") {
    hWnd := WinExist( "Battery Meter ahk_class SystemTray_Main" )
    PostMessage, 1226, 1226, 0x201,, ahk_id %hWnd% ; Left Click Down
    PostMessage, 1226, 1226, 0x202,, ahk_id %hWnd% ; Left Click Up
    WinWaitActive, ahk_id %hWnd%,,1                ; Wait for SRH Tray left-click-Menu
    ControlSend,,{Down}{Down},ahk_id %hWnd%        ; Select the first menu Item
  }
}
The original code had "Power Meter" instead of "Battery Meter" - perhaps I did some research back then and changed that on my own (I'm using a laptop)

For a couple of years it worked perfectly fine on Windows 10 x64 - I hit my key combo and it opens the context menu where I can choose a USB device to eject.
It usually worked way faster than doing so the regular way - opening "hidden icons" tray and clicking the right icon.

Unfortunately after the latest Win10 update (version 1709 build 16299.192) this function isn't working anymore. The hWnd is being returned by WinExist but nothing else happens.
Does anybody know how to make it pop the context menu again?

Thanks
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Pop "Safely Remove Hardware" menu from Win10 tray

11 Feb 2018, 15:23

- You could try this, just in case in works.

Code: Select all

q:: ;Explorer - open Safely Remove Hardware
Run, control hotplug.dll
return
- From:
jeeswg's Explorer tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=31755
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
mrdev
Posts: 5
Joined: 11 Feb 2018, 13:54

Re: Pop "Safely Remove Hardware" menu from Win10 tray

11 Feb 2018, 17:06

jeeswg wrote:Run, control hotplug.dll
While this works, it's not as convenient as clicking an item from the context menu. Thank you for you contribution nevertheless!
User avatar
mrdev
Posts: 5
Joined: 11 Feb 2018, 13:54

Re: Pop "Safely Remove Hardware" menu from Win10 tray

15 Mar 2018, 14:44

Sorry for bumping, but I'm still hoping to get some help on this issue.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Pop "Safely Remove Hardware" menu from Win10 tray

15 Mar 2018, 15:26

This works for me on Windows 7, it's basically the same method. One key thing is to make sure that DetectHiddenWindows is on. You could also try running the script in admin mode.

Code: Select all

;tested on Windows 7
q:: ;show Safely Remove Hardware menu and focus first drive
vDHW := A_DetectHiddenWindows
DetectHiddenWindows, On
if hWnd := WinExist("Battery Meter ahk_class SystemTray_Main")
{
	PostMessage, 1226,, 0x201,, % "ahk_id " hWnd ;WM_LBUTTONDOWN := 0x201
	PostMessage, 1226,, 0x202,, % "ahk_id " hWnd ;WM_LBUTTONUP := 0x202
	vIndex := 4
	DetectHiddenWindows, Off
	WinWait, ahk_class #32768
	PostMessage, 0x1E5, % vIndex-1, 0,, ahk_class #32768 ;MN_SELECTITEM := 0x1E5 ;focus item
}
DetectHiddenWindows, % vDHW
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
mrdev
Posts: 5
Joined: 11 Feb 2018, 13:54

Re: Pop "Safely Remove Hardware" menu from Win10 tray

17 Mar 2018, 18:24

Thanks. Unfortunately it doesn't seem to work on win10
User avatar
mrdev
Posts: 5
Joined: 11 Feb 2018, 13:54

Re: Pop "Safely Remove Hardware" menu from Win10 tray

21 Oct 2020, 22:13

A couple of years later I'm still bummed it doesn't work. Can anyone more knowledgeable look into this please?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Chunjee and 141 guests