Jump to content

pause the script until a Removable device is inserted


 Share

Recommended Posts

hi, i am automating a wireless drivers installation setup. therefore i need to know...

1- how to pause the script until a Removable device is inserted?

2- how to safely remove a removable device?

many thanks in advance for the help!

[font="Georgia"]GSM Expert[/font] but not AutoIt :DProud to be Admin Of : http://www.gsmhosting.net/visit my Forum... http://www.gsmhosting.net/vbb/index.php
$Life = "Happy"
If @Error Then
$Life = "Risk"
Link to comment
Share on other sites

maybe this can help you, it's from one of my scripts...

#include <Process.au3>
#include <Constants.au3>
#NoTrayIcon

Global $UsbDrive

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown.

Call("USBListen")
; FunctionsTraySetState()
Func USBListen()
    
$strComputer = "."
 $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")

 $colEvents = $objWMIService.ExecNotificationQuery _
    ("Select * From __InstanceOperationEvent Within 5 Where " _
        & "TargetInstance isa 'Win32_LogicalDisk'")
        
While 1
     $objEvent = $colEvents.NextEvent
    If $objEvent.TargetInstance.DriveType = 2 Then
        Select
        Case $objEvent.Path_.Class()="__InstanceCreationEvent"
                $UsbDrive = $objEvent.TargetInstance.DeviceId
                TraySetIcon("warning")
                TraySetState()
                TraySetToolTip($objEvent.TargetInstance.DeviceId)
                TrayTip("","Drive " & $objEvent.TargetInstance.DeviceId & " has been added." & @CR,3,0)
                Sleep(500)
                _RunDOS("start " & $objEvent.TargetInstance.DeviceId & "\test.txt")
            Case $objEvent.Path_.Class()="__InstanceDeletionEvent"
                TraySetToolTip($objEvent.TargetInstance.DeviceId)
                TrayTip("","Drive " & $objEvent.TargetInstance.DeviceId & " has been removed."& @CR,3,0)
                Sleep(3000)
                TraySetState(2)
        EndSelect
    EndIf
WEnd
EndFunc

Func ExitEvent()
    Exit
EndFunc

Also, post your script and I'll try and edit it to do what you want if you can't

Edited by AoRaToS

s!mpL3 LAN Messenger

Current version 2.9.9.1 [04/07/2019]

s!mpL3 LAN Messenger.zip

s!mpL3

Link to comment
Share on other sites

thanks a lot but i have also tried and succeed...

something like this

$DISK = DriveGetDrive("REMOVABLE")
For $I = 1 To $DISK[0]
    $STATS = DriveStatus($DISK[$I])
    If $STATS = "READY" Then
    Msgbox(0, "Whatever", "Drive is ready")
    EndIf
Next

can i do it by some other way?

Edited by zFrank
[font="Georgia"]GSM Expert[/font] but not AutoIt :DProud to be Admin Of : http://www.gsmhosting.net/visit my Forum... http://www.gsmhosting.net/vbb/index.php
$Life = "Happy"
If @Error Then
$Life = "Risk"
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...