c.haslam Posted April 16, 2008 Share Posted April 16, 2008 Consider the following code: Opt("GUIOnEventMode", 1) Global $cancelled = False,$inserted = False MyShowDialog() Func MyShowDialog() $Form1 = GUICreate("Form1", 212, 92, 193, 115) GUICtrlCreateLabel("Waiting for you to insert USB stick", 16, 16, 165, 17) $cancel = GUICtrlCreateButton("Cancel", 120, 48, 65, 25, 0) GUICtrlSetOnEvent($cancel,"ClickedOnCancel") GUISetState(@SW_SHOW) While Not ($cancelled or $inserted) Sleep(100) WEnd GUIDelete($Form1) EndFunc Func ClickedOnCancel() $cancelled = True EndFunc How do I set $inserted to true when the user inserts a USB stick labelled "Documents"? Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
monoceres Posted April 16, 2008 Share Posted April 16, 2008 Full example: $bool = False While 1 Sleep(1000) If Not $bool Then $drives = DriveGetDrive("REMOVABLE") If $drives <> "" Then For $drive In $drives If DriveGetLabel($drive) == "Documents" Then $bool = True MsgBox(0, "Permission Granted", "The right USB stick was inserted!") ExitLoop 2 EndIf Next EndIf EndIf WEnd Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Xenobiologist Posted April 17, 2008 Share Posted April 17, 2008 Hi, Opt('MustDeclareVars', 1) MsgBox(0, 0, _getNewUSB()) Func _getNewUSB() Local $strComputer = ".", $objEvent = 0 Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") Local $colEvents = $objWMIService.ExecNotificationQuery _ ("Select * From __InstanceOperationEvent Within 5 Where " _ & "TargetInstance isa 'Win32_LogicalDisk'") While 1 $objEvent = $colEvents.NextEvent If $objEvent.TargetInstance.DriveType = 2 Then If $objEvent.Path_.Class() = "__InstanceCreationEvent" Then Return $objEvent.TargetInstance.DeviceId EndIf Sleep(10) WEnd EndFunc ;==>_getNewUSB Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
c.haslam Posted April 19, 2008 Author Share Posted April 19, 2008 Many thanks to you both. ...chris Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now