Quantcast
Channel: AutoHotkey Community
Viewing all articles
Browse latest Browse all 579

Ask for Help (v1) • Re: List of USB serial numbers

$
0
0
after complicated made , here an easy logic script ( I think ... ) , driveget serial only from new inserted disk ( not show GUI with all drives )
;- Detect Usb Drive ( from user @teadrinker )
;- viewtopic.php?t=76221&p=330409

CODE:

;- Detect Usb Drive  ( from user 'teadrinker' )
;- https://www.autohotkey.com/boards/viewtopic.php?t=76221&p=330409
;-
;- MODIFIED = 20240331
;- CREATED = 20240331
;-

#Requires AutoHotkey v1.1.33.11
#warn
#NoEnv
#Singleinstance,force
Setworkingdir,%a_scriptdir%
global serial1,letter
OnMessage(0x219, "WM_DEVICECHANGE")
return
;----------------------------
EventHandler(letter, event)
{
if event
{
drv:=letter . ":\"
msgbox, 262208, ,%drv% < PLUGGED IN,3
DriveGet,serial1,serial,%DRV%
gosub,A1
}
else
msgbox, 262208, ,%letter% > is removed,3
return
}
;-------------
A1:
serialx:="2328642094,2565867498,3000530768,0123456789"
if serial1 in %serialx%
{
if (serial1="2328642094")
{
Process,Exist,charmap.exe
If Not ErrorLevel
try,run,Charmap
try,run,%letter%:\Test_msgbox.ahk ; try to run a program 'Test_msgbox.ahk' from this USB-DEVICE
}
if (serial1="2565867498")
{
Process,Exist,notepad.exe
If Not ErrorLevel
try,run,Notepad
}
}
else
{
msgbox, 262208,Serial NOT FOUND, Drive DEVICE-USB with the desired Serial-Number NOT FOUND in:`n%serialx%,5
try,run,::{20d04fe0-3aea-1069-a2d8-08002b30309d}
}
return
;==========================
;------------------
WM_DEVICECHANGE(wp, lp)
{ ;- user 'teadrinker' https://www.autohotkey.com/boards/viewtopic.php?t=76221&p=330409
static DBT_DEVICEARRIVAL := 0x8000, DBT_DEVICEREMOVECOMPLETE := 0x8004, DBT_DEVTYP_VOLUME := 2
if NumGet(lp + 4, "UInt") = DBT_DEVTYP_VOLUME && (wp = DBT_DEVICEARRIVAL || wp = DBT_DEVICEREMOVECOMPLETE) {
dbcv_unitmask := NumGet(lp + 12, "UInt")
letter := Chr(Asc("A") + ln(dbcv_unitmask)/ln(2))
timer := Func("EventHandler").Bind(letter, wp = DBT_DEVICEARRIVAL)
SetTimer, % timer, -10
}
}
;=====================================
esc::exitapp
;=====================================
;- a test-script which is in NEW inserted drive to run as test
/*
;-Test_msgbox.ahk
F1:=a_scriptfullpath
SplitPath,f1, name, dir, ext, name_no_ext, drive
msgbox, 262208,%f1%,%f1% = This USB-DEVICE drive is > %drive%
;run,notepad "%f1%"
return
*/
;==================================================================

Statistics: Posted by garry — Today, 15:17



Viewing all articles
Browse latest Browse all 579

Trending Articles