Jump to content
Sign in to follow this  
gseller

USB Monitor and open

Recommended Posts

gseller

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...

Share this post


Link to post
Share on other sites
PeterAtkin

Awsome thanks this is just what i was looking for your a life saver..

Edited by PeterAtkin

[topic='115020'] AD Domain Logon Script[/topic]

Share this post


Link to post
Share on other sites
rajeshontheweb

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

Share this post


Link to post
Share on other sites
dmob

Wonderful, this is useful; I have also turned off autorun in my cafe

so this will save time for me and my customers.

Thanks for sharing.

Share this post


Link to post
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
Sign in to follow this  

×