Jump to content

USB Monitor and open


gseller
 Share

Recommended Posts

Hey All, Been a while since I posted anything so Here is a small USB Monitor I put together with most corporate worlds turning off autorun feature which is a good thing. I hate having to go to my gomputer each time I slap in a flashdrive.

This small script can be running in background and sees the drive and alerts you then opens the root folder. This way no autorun stuff is invoked but you get quick access to your drive.

;#NoTrayIcon
$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"
         SplashTextOn( "", "DRIVE: " & $objEvent.TargetInstance.DeviceId & " INSERTED, OPENING ROOT FOLDER."& @CR, 300, 75, -1, -1,17 )
         Sleep(2000)
         SplashOff()
    $val = ShellExecute("", "", $objEvent.TargetInstance.DeviceId, "open")
            Case $objEvent.Path_.Class()="__InstanceDeletionEvent"
         SplashTextOn( "", "DRIVE: " & $objEvent.TargetInstance.DeviceId & " HAS BEEN REMOVED."& @CR, 300, 75, -1, -1,17 )
         Sleep(2000)
         SplashOff()
        EndSelect
    EndIf
WEnd
Sort and sweet. Hope it is handy for someone...
Link to comment
Share on other sites

  • 6 months later...

its nice, but one suggestion,

i would like the use of

$val = Run("explorer.exe /e ,"  & $objEvent.TargetInstance.DeviceId )
rather than open verb because in many a case, if the autorun virus has already infected the pc, then u would end up with this.

Posted Image

Edited by rajeshontheweb
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...