Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #RequireAdmin
- Global $DBT_DEVNODES_CHANGED = 0x0007
- Global $DBT_DEVTYP_OEM = 0x00000000
- Global $DBT_DEVTYP_DEVNODE = 0x00000001
- Global $DBT_DEVTYP_VOLUME = 0x00000002
- Global $DBT_DEVTYP_PORT = 0x00000003
- Global $DBT_DEVTYP_NET = 0x00000004
- Global Const $WM_DEVICECHANGE = 0x0219
- Global Const $DBT_DEVICEARRIVAL = 0x8000
- Global Const $DBT_DEVICEREMOVECOMPLETE = 0x8004
- Global Const $GUI_RUNDEFMSG = 'GUI_RUNDEFMSG'
- $Gui = GUICreate("WM_DEVICECHANGE", 280, 100)
- $ControlID = GUICtrlCreateLabel('WM_DEVICECHANGE function is performed when connecting or disconnecting devices to the system.' & @CRLF & 'Try inserting the stick', 5, 5, 270, 70)
- GUISetState()
- GUIRegisterMsg($WM_DEVICECHANGE, "WM_DEVICECHANGE")
- Do
- Until GUIGetMsg() = -3
- Func WM_DEVICECHANGE($hWnd, $Msg, $wParam, $lParam)
- WinSetTitle($Gui, '', 'Device Connection')
- If ($wParam = $DBT_DEVICEARRIVAL) Or ($wParam = $DBT_DEVICEREMOVECOMPLETE) Then
- Local $DEV_BROADCAST_VOLUME = DllStructCreate("int dbcvsize;int dbcvdevicetype;int dbcvreserved;int dbcvunitmask;" & _
- "ushort dbcvflags", $lParam)
- Local $iDriveType = DllStructGetData($DEV_BROADCAST_VOLUME, "dbcvdevicetype")
- Else
- Return $GUI_RUNDEFMSG
- EndIf
- ; If the device is not a logical drive, the output of the function
- If $iDriveType <> $DBT_DEVTYP_VOLUME Then Return $GUI_RUNDEFMSG
- Local $iMask = DllStructGetData($DEV_BROADCAST_VOLUME, "dbcvunitmask")
- $iMask = Log($iMask) / Log(2)
- Local $iDrive = Chr(65 + $iMask) & ":"
- Switch $wParam
- Case $DBT_DEVICEARRIVAL ; detection device
- TrayTip("WM_DEVICECHANGE", "device connected", 5, 1)
- GUICtrlSetData($ControlID, "device connected")
- Case $DBT_DEVICEREMOVECOMPLETE ; Disconnecting
- TrayTip("WM_DEVICECHANGE", "device disconnected", 5, 2)
- GUICtrlSetData($ControlID, "device disconnected")
- EndSwitch
- Return $GUI_RUNDEFMSG
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement