Jump to content

cimv2 object help


Recommended Posts

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 by senthor
Link to comment
Share on other sites

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?

:P

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

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.

:P

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

$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 by senthor
Link to comment
Share on other sites

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

:P

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

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