senthor Posted August 14, 2008 Share Posted August 14, 2008 (edited) Hello everyone! I'm currently trying to create a script were I need to recognize if a drive is connected. It shouldn't take too long cause it will be looped. AND it should be without floppy access. (Maybe Win32_LogicalDisk without class floppy drives??) till now I have: $strComputer = "." $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $objEvent = $objWMIService.ExecNotificationQuery _ ("Select * From __InstanceOperationEvent Within 5 Where " _ & "TargetInstance isa 'Win32_LogicalDisk' and " _ & "TargetInstance.DriveType = 2" ) While True If $objEvent.TargetInstance.DriveType = 2 Then If $objEvent.Path_.Class()="__InstanceCreationEvent" ~some code~ Else ~some other code~ EndIf EndIf Sleep(10) WEnd Otherwise, it would be OK if it would only list all drives without any floppy drives and access. It shouldn't take too long cause it will be looped. Thank you! Edited August 14, 2008 by senthor FileListToArray UDFMy tools Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 14, 2008 Share Posted August 14, 2008 Hello everyone! I'm currently trying to create a script were I need to recognize if a drive is connected. It shouldn't take too long cause it will be looped. AND it should be without floppy access. (Maybe Win32_LogicalDisk without class floppy drives??) till now I have: $strComputer = "." $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $objEvent = $objWMIService.ExecNotificationQuery _ ("Select * From __InstanceOperationEvent Within 5 Where " _ & "TargetInstance isa 'Win32_LogicalDisk' and " _ & "TargetInstance.DriveType = 2" ) While True If $objEvent.TargetInstance.DriveType = 2 Then If $objEvent.Path_.Class()="__InstanceCreationEvent" ~some code~ Else ~some other code~ EndIf EndIf Sleep(10) WEnd Otherwise, it would be OK if it would only list all drives without any floppy drives and access. It shouldn't take too long cause it will be looped. Thank you! So... what happens when you run it? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
senthor Posted August 14, 2008 Author Share Posted August 14, 2008 So... what happens when you run it? My floppy drive gets accessed and it takes about 5-8 seconds to check drives. ;-( FileListToArray UDFMy tools Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 14, 2008 Share Posted August 14, 2008 My floppy drive gets accessed and it takes about 5-8 seconds to check drives. ;-(Well, DriveType = 2 is removable drives, which includes floppies.Limit the collection more by also specifying .MediaType, perhaps .MediaType = 11 or 12. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
senthor Posted August 14, 2008 Author Share Posted August 14, 2008 (edited) $strComputer = "." $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $objEvent = $objWMIService.ExecNotificationQuery _ ("Select * From __InstanceOperationEvent Within 5 Where " _ & "TargetInstance isa 'Win32_LogicalDisk' and " _ & "TargetInstance.DriveType = 2" ) While True $objEvent = $objEvent.NextEvent If $objEvent.TargetInstance.MediaType = 10 or $objEvent.TargetInstance.MediaType = 11 Then If $objEvent.Path_.Class()="__InstanceCreationEvent" ~some code~ Else ~some other code~ EndIf EndIf Sleep(10) WEnd works, but takes a while too... Edited August 14, 2008 by senthor FileListToArray UDFMy tools Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 14, 2008 Share Posted August 14, 2008 $strComputer = "." $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $objEvent = $objWMIService.ExecNotificationQuery _ ("Select * From __InstanceOperationEvent Within 5 Where " _ & "TargetInstance isa 'Win32_LogicalDisk' and " _ & "TargetInstance.DriveType = 2" ) While True $objEvent = $objEvent.NextEvent If $objEvent.TargetInstance.MediaType = 10 or $objEvent.TargetInstance.MediaType = 11 Then If $objEvent.Path_.Class()="__InstanceCreationEvent" ~some code~ Else ~some other code~ EndIf EndIf Sleep(10) WEnd works, but takes a while too... I meant add it as another "and" condition in your query. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
senthor Posted August 14, 2008 Author Share Posted August 14, 2008 (edited) but I need media type 10 and 11. how to add this in query?http://msdn.microsoft.com/en-us/library/aa394173.aspx[EDIT]Doesn't works. Media type of flash drive: nothing. ??? [/EDIT] Edited August 14, 2008 by senthor FileListToArray UDFMy tools 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