Code: Select all
DriveGet , serial2 , serial , %last%
if (serial2 in "4383746507,2957886184,7333182867") ; LIST OF SERIAL NUMBERS
{ msg USB NOT RECOGNIZED}
else
{ run,::{20d04fe0-3aea-1069-a2d8-08002b30309d} }
return
Code: Select all
DriveGet , serial2 , serial , %last%
if (serial2 in "4383746507,2957886184,7333182867") ; LIST OF SERIAL NUMBERS
{ msg USB NOT RECOGNIZED}
else
{ run,::{20d04fe0-3aea-1069-a2d8-08002b30309d} }
return
I tried your suggestion. It seems script's msg box pops up regardless of whether the serial numbers match with current plugged-in USB one.JoeWinograd wrote: ↑28 Mar 2024, 21:07I haven't looked at garry's script, but knowing garry, I assure you that he did not have this line:
YES! got it. Can I inquire how do I divide those actions such as if the serial number were to match a certain serial number, it'll open explorer.exe. If it matches the another one, it'll run notepad.exe, so on and so forth.JoeWinograd wrote: ↑28 Mar 2024, 21:25I think you are trying to see if the serial number that comes back from the DriveGet command (in the serial2 variable) matches one of the serial numbers in a list. Is that right?
Code: Select all
Switch serial2
{
Case "111","222","333":
Run,explorer.exe
Case "aaa","bbb","ccc":
Run,notepad.exe
Default:
Msgbox,262192,Error,Serial number not recognized:`n`n%serial2%
}
Code: Select all
DriveGet , serial2 , serial , %last% ;- volume serial number
Switch serial2
{
Case 2957886184:
Run,explorer.exe
Case 9383746507:
Run,notepad.exe
Default:
Msgbox,262192,Error,Serial number not recognized:`n`n%serial2%
}
return
esc::exitapp
Code: Select all
;- MODIFIED = 20240329/2
;- CREATED = 20240329
;-
#Requires AutoHotkey v1.1.33.11
#Warn
#NoEnv
;-
serialx:="2565867498,3000530768,0123456789" ;- <<<< add wanted serialnumbers
;-
DetectHiddenWindows, On
Setworkingdir,%a_scriptdir%
setformat,float,0.2
SendMode Input
SetBatchLines -1
SetWinDelay, 0
filename1:="Active Drives / ESC= minimize / F9= Show again "
Gui,2:default
wa:=A_screenwidth,ha:=A_screenHeight,xx:=100
Gui,2: -dpiscale
;- maybe change fontsize
;============ GUISIZEx DPIx 4Kx 3840*2160 is 100% ============
if (wa=3840)
Gui,2:Font,s12 ,Lucida Console
;============ GUISIZEx DPIx FHD 1920*1080 is 100% ============
else if (wa=1920)
Gui,2:Font,s10 ,Lucida Console
else
Gui,2:Font,s8 ,Lucida Console
;=============================================================
;Gui, -MaximizeBox -MinimizeBox +AlwaysOnTop
Gui,+AlwaysOnTop
Gui,2:color,black,black
;Gui,2: font,s10,Tahoma
Gui,2: Margin,0,0
T1:=(wa*3)/xx,T2:=(wa*5)/xx,T3:=(wa*5)/xx,T4:=(wa*5)/xx,T5:=(wa*5)/xx,T6:=(wa*5)/xx,T7:=(wa*5)/xx,T8:=(wa*5)/xx,T9:=(wa*5)/xx,T10:=(wa*7)/xx,T11:=(wa*10)/xx,T12:=(wa*5)/xx
diff1:=(wa*2)/xx
wlv:=(t1+t2+t3+t4+t5+t6+t7+t8+t9+t10+t11+t12+diff1)
x:=(wa*1)/xx,y:=(ha*1)/xx,h:=(ha*14)/xx
col:="F0F0F0"
Gui,2: Add, ListView,x%x% y%y% w%wlv% h%h% Grid vLV1 +altsubmit background%col%, Drive|STATUS|TYPE|FORMAT|Capacity-MB|FREE-MB|Capacity-GB|FREE-GB|Procent|SerialNR|LABEL|StatusCD
LV_ModifyCol(1,T1),LV_ModifyCol(2,T2),LV_ModifyCol(2,T2 "Center"),LV_ModifyCol(3,T3),LV_ModifyCol(3,"Center"),LV_ModifyCol(4,T4),LV_ModifyCol(4,"Center"),LV_ModifyCol(5,T5),LV_ModifyCol(5,"Right"),
LV_ModifyCol(6,T6),LV_ModifyCol(6,"Right"),LV_ModifyCol(7,T7),LV_ModifyCol(7,"Right"),LV_ModifyCol(8,T8),LV_ModifyCol(8,"Right"),LV_ModifyCol(9,T9),LV_ModifyCol(9,"Center"),
LV_ModifyCol(10,T10),LV_ModifyCol(10,"Right"),LV_ModifyCol(11,T11),LV_ModifyCol(11,"Right"),LV_ModifyCol(12,T12),LV_ModifyCol(12,"Center")
x:=(wa*1)/xx,y:=(ha*16.5)/xx
Gui,2: add,edit, x%x% y%y% w%wlv% r1 cyellow vED1,
wg:=(wlv+diff1)
x:=(wa*2)/xx,y:=(ha*2)/xx,h:=(ha*21)/xx
Gui,2: Show,x%x% y%y% w%wg% h%h% ,%filename1%
gosub,drivegetshow
OnMessage(0x219, "notify_change")
Return
;---------------
2GuiClose:
exitapp
;---------------
~ESC::
Gui,2:minimize
return
;---------------
notify_change(wParam, lParam, msg, hwnd)
{
Gui,2: Show,
gosub,drivegetshow
}
;---------------
~$F9::
Gui,2: Show,
drivegetshow:
Guicontrol,2:,ED1,
LV_Delete()
I:=0
DriveGet, A, List,
allserial:=""
loop,10
d%a_index%:=""
loop,parse,A
{
i++
type1:="",cap1:="",free1:="",fs1:="",label1:="",serial1:="",status1:="",statusCD:="",drv:=""
x:=a_loopfield
drv=%x%:\
DriveGet , type1 , type , %DRV% ;- removable / fixed
DriveGet , cap1 , capacity , %DRV%
DrivespaceFree , free1 , %DRV%
DriveGet , fs1 , fs , %DRV% ;- FAT
DriveGet , label1 , label , %DRV% ;- volume label >\\server1
DriveGet , serial1 , serial , %DRV% ;- volume serial number
DriveGet , status1 , status , %DRV%
DriveGet , statusCD, StatusCD , %DRV% ;- CDRom CDFS Audio CD open / stopped
prc :=(free1*100)/cap1
cap1a :=StrReplace(cap1 , Substr(cap1 , -2), "'" Substr(cap1 , -2))
free1a:=StrReplace(free1, Substr(free1, -2), "'" Substr(free1, -2))
cap2 :=Floor(cap1 /1024)
free2 :=Floor(free1/1024)
allserial .= serial1 . ","
d%i% := serial1
if (type1="CDROM")
LV_Add("", drv,status1,type1,fs1,,,,,,serial1,label1,statuscd)
else
LV_Add("", drv,status1,type1,fs1,cap1a,free1a,cap2,free2,prc . " %",serial1,label1,statuscd)
}
u:=0, e:=""
loop,parse,serialx,`,
{
u++
y:=a_loopfield
if Y=
continue
f:=d%u%
if f in %serialx%
e .= f . ","
}
stringtrimright,e,e,1
if e<>
Guicontrol,2:,ED1,HERE the SEARCHED SERIAL-Numbers > %e%
else
Guicontrol,2:,ED1,
return
;==========================================================
Code: Select all
#persistent
OnMessage(0x219, "notify_change")
notify_change(wParam, lParam, msg, hwnd)
{
settimer,checkdrive,2000
}
return
checkdrive:
i=0
alldrives:=""
DriveGet, A, List,
StringSplit,D, A,
loop,%d0%
{
DRV:= % d%a_index% . ":\"
i++
DriveGet , type1 , type , %DRV% ;- removable / fixed
DriveGet , cap1 , capacity , %DRV%
DrivespaceFree , free1 , %DRV%
DriveGet , fs1 , fs , %DRV% ;- FAT
DriveGet , label1 , label , %DRV% ;- volume label >\\server1
DriveGet , serial1 , serial , %DRV% ;- volume serial number
DriveGet , status1 , status , %DRV%
alldrives .= drv . " " . type1 . " " . free1 . "-MB`n"
}
VT:=D0 ;- totaldrives
last = %drv%
DriveGet , serial2 , serial , %last% ;- volume serial number
Switch serial2
{
Case 2957886184:
Run,explorer.exe
Case 9383746507:
Run,notepad.exe
Default:
Msgbox,262192,Error,Serial number not recognized:`n`n%serial2%
}
return
esc::exitapp
Hi, Thankyou for your help. In your new example, I do not know where to insert the switch example provided by JoeWinograd. There's a lot of material in that script.
Code: Select all
;- List of USB serial numbers
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=127973
;-
;- MODIFIED = 20240331/2
;- CREATED = 20240329
;-
#Requires AutoHotkey v1.1.33.11
#Warn
#NoEnv
;-
serialx:="2328642094,2565867498,3000530768,0123456789" ;- <<<< add wanted serialnumbers
;-
DetectHiddenWindows, On
Setworkingdir,%a_scriptdir%
setformat,float,0.2
SendMode Input
SetBatchLines -1
SetWinDelay, 0
filename1:="Active Drives / ESC= minimize / F9= Show again "
Gui,2:default
device:="",usbx:=""
global device,usbx
wa:=A_screenwidth,ha:=A_screenHeight,xx:=100
Gui,2: -dpiscale hwndUID
;- maybe change fontsize
;============ GUISIZEx DPIx 4Kx 3840*2160 is 100% ============
if (wa=3840)
Gui,2:Font,s12 ,Lucida Console
;============ GUISIZEx DPIx FHD 1920*1080 is 100% ============
else if (wa=1920)
Gui,2:Font,s10 ,Lucida Console
else
Gui,2:Font,s8 ,Lucida Console
;=============================================================
;Gui, -MaximizeBox -MinimizeBox +AlwaysOnTop
Gui,+AlwaysOnTop
Gui,2:color,black,black
;Gui,2: font,s10,Tahoma
Gui,2: Margin,0,0
T1:=(wa*3)/xx,T2:=(wa*5)/xx,T3:=(wa*5)/xx,T4:=(wa*5)/xx,T5:=(wa*5)/xx,T6:=(wa*5)/xx,T7:=(wa*5)/xx,T8:=(wa*5)/xx,T9:=(wa*5)/xx,T10:=(wa*7)/xx,T11:=(wa*10)/xx,T12:=(wa*5)/xx
diff1:=(wa*2)/xx
wlv:=(t1+t2+t3+t4+t5+t6+t7+t8+t9+t10+t11+t12+diff1)
x:=(wa*1)/xx,y:=(ha*1)/xx,h:=(ha*14)/xx
col:="F0F0F0"
Gui,2: Add, ListView,x%x% y%y% w%wlv% h%h% Grid vLV1 +altsubmit background%col%, Drive|STATUS|TYPE|FORMAT|Capacity-MB|FREE-MB|Capacity-GB|FREE-GB|Procent|SerialNR|LABEL|StatusCD
LV_ModifyCol(1,T1),LV_ModifyCol(2,T2),LV_ModifyCol(2,T2 "Center"),LV_ModifyCol(3,T3),LV_ModifyCol(3,"Center"),LV_ModifyCol(4,T4),LV_ModifyCol(4,"Center"),LV_ModifyCol(5,T5),LV_ModifyCol(5,"Right"),
LV_ModifyCol(6,T6),LV_ModifyCol(6,"Right"),LV_ModifyCol(7,T7),LV_ModifyCol(7,"Right"),LV_ModifyCol(8,T8),LV_ModifyCol(8,"Right"),LV_ModifyCol(9,T9),LV_ModifyCol(9,"Center"),
LV_ModifyCol(10,T10),LV_ModifyCol(10,"Right"),LV_ModifyCol(11,T11),LV_ModifyCol(11,"Right"),LV_ModifyCol(12,T12),LV_ModifyCol(12,"Center")
x:=(wa*1)/xx,y:=(ha*16.5)/xx
Gui,2: add,edit, x%x% y%y% w%wlv% r1 cyellow vED1,
wg:=(wlv+diff1)
x:=(wa*2)/xx,y:=(ha*2)/xx,h:=(ha*21)/xx
Gui,2: Show,Hide x%x% y%y% w%wg% h%h% ,%filename1%
firstrun:=0
gosub,drivegetshow
OnMessage(0x0219, "WM_DEVICECHANGE")
Return
;---------------
2GuiClose:
exitapp
;---------------
~ESC::
Gui,2:minimize
return
;---------------
;---------------
~$F9::
Gui,2: Show,
;--------------
drivegetshow:
Guicontrol,2:,ED1,
LV_Delete()
I:=0
DriveGet, A, List,
allserial:=""
loop,10
d%a_index%:=""
loop,parse,A
{
i++
type1:="",cap1:="",free1:="",fs1:="",label1:="",serial1:="",status1:="",statusCD:="",drv:=""
x:=a_loopfield
drv=%x%:\
DriveGet , type1 , type , %DRV% ;- removable / fixed
DriveGet , cap1 , capacity , %DRV%
DrivespaceFree , free1 , %DRV%
DriveGet , fs1 , fs , %DRV% ;- FAT
DriveGet , label1 , label , %DRV% ;- volume label >\\server1
DriveGet , serial1 , serial , %DRV% ;- volume serial number
DriveGet , status1 , status , %DRV%
DriveGet , statusCD, StatusCD , %DRV% ;- CDRom CDFS Audio CD open / stopped
prc :=(free1*100)/cap1
cap1a :=StrReplace(cap1 , Substr(cap1 , -2), "'" Substr(cap1 , -2))
free1a:=StrReplace(free1, Substr(free1, -2), "'" Substr(free1, -2))
cap2 :=Floor(cap1 /1024)
free2 :=Floor(free1/1024)
allserial .= serial1 . ","
d%i% := serial1
if (type1="CDROM")
LV_Add("", drv,status1,type1,fs1,,,,,,serial1,label1,statuscd)
else
LV_Add("", drv,status1,type1,fs1,cap1a,free1a,cap2,free2,prc . " %",serial1,label1,statuscd)
}
u:=0, e:=""
loop,parse,serialx,`,
{
u++
y:=a_loopfield
if Y=
continue
f:=d%u%
if f in %serialx%
e .= f . ","
}
stringtrimright,e,e,1
if e<>
{
Firstrun++
Guicontrol,2:,ED1,Show defined SerialNumbers %e%
if (Firstrun=1)
gosub,a1
}
else
Guicontrol,2:,ED1,
return
;=================================================================
;- a test-script to run from NEW inserted drive
/*
;-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
*/
;==================================================================
A1:
succ=0
loop,parse,e,`,
{
k:=a_loopfield
if (k="2328642094")
{
succ=1
Process,Exist,charmap.exe
If Not ErrorLevel
try,run,Charmap
sch:="ahk_exe charmap.exe"
try,run,%usbx%Test_msgbox.ahk ; try to run a program Test_msgbox.ahk from this USB-DEVICE
sleep,1000
}
else if (k="2565867498")
{
succ=1
Process,Exist,notepad.exe
If Not ErrorLevel
try,run,Notepad
sc:="ahk_exe notepad.exe"
sleep,1000
}
}
if succ=0
{
msgbox, 262208,Serial NOT FOUND, Drive DEVICE-USB with the desired Serial-Number NOT FOUND`n%serialx%,5
;run,::{20d04fe0-3aea-1069-a2d8-08002b30309d}
}
return
;---------------------------------
WM_DEVICECHANGE(wParam, lParam)
{
static init := OnMessage(0x0219, "WM_DEVICECHANGE")
if (wParam = 0x8000) || (wParam = 0x8004) && ((NumGet(lParam+4, "uint")) = 0x2) {
m := 0, mask := NumGet(lParam+12, "uint")
while (mask > 1) && (++m < 0x1A)
mask >>= 1
DeviceChangeInfo(Chr(0x41 + m) ":\", wParam)
}
}
DeviceChangeInfo(device, state)
{
;Gui,2: Show,
sleep,1000
gosub,drivegetshow
if (state=0x8000)
{
msgbox, 262208, ,%device% plugged in,5
USBX:=device
gosub,A1
}
if (state=0x8004)
msgbox, 262208, ,%device% is removed,5
return
}
;==========================================================
Code: Select all
;- 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
*/
;==================================================================
Users browsing this forum: peter_ahk and 62 guests