Floppy/CD drive check with WMI and a related question

(imported topic written by rad.ricka91)

Hi,

here’s my take on floppy/CD in drive check.

(type of select “FreeSpace from Win32_LogicalDisk where DriveType=2 and DeviceID=‘A:’” of wmi) as integer = 8

(type of select “FreeSpace from Win32_LogicalDisk where DriveType=5 and DeviceID=‘D:’” of wmi) as integer = 8

Obviously it’s really easy to spot the limitation - it is hardcoded to a specific drive letter!

So here is my suggestion - it would be great if we could have a WMI iterator that would let you evaluate a collection returned by WMI and possibly even return an array of values. As it is you have to ensure that the WMI query returns a singular object.

For example

imaginary code start

################

Q: ((select “DeviceID from Win32_LogicalDisk where DriveType=5” of wmi) as array of string) as string

A: D:, F: (as opposed to the “Singular expression referes to non-unique object.” currently being returned)

and

Q: collection of ((type of select “FreeSpace from Win32_LogicalDisk where DriveType=5” of wmi) as array of integer) = 8

A: True if at least one of the values in the collection = 8, False if none

################

imaginary code end

What do you think, would this be of any value to anyone? Or would it just mean a huge headache for BigFix developers because it introduces new primitive object? :smiley:

Regards,

Rad

PS: If you are gonna use the two expressions to check for floopy and CD don’t forget to set the “Evaluate every” value to something more than every report as they are quite costly in CPU terms.

(imported comment written by brolly3391)

Assuming Windows OS since you mentioned Windows Management Interface.

color=red

q:[/color] names

color=blue

of[/color] drives

color=blue

whose[/color] ((type

color=blue

of it [/color]= “DRIVE_REMOVABLE”

color=blue

OR[/color] type

color=blue

of it[/color] = “DRIVE_CDROM”) and (

color=blue

exists[/color] file system type

color=blue

of it[/color]))

color=red

A:[/color] A:

color=red

A:[/color] D:

color=red

A:[/color] E:

color=red

T:[/color] 2851.361 ms

color=red

I:[/color] plural string

I had a floppy, a CD and a jump drive inserted. It is slow, because it is actually spinning up the drives. With no removable drives or CDs inserted I get:

color=red

q:[/color] names

color=blue

of[/color] drives

color=blue

whose[/color] ((type

color=blue

of it [/color]= “DRIVE_REMOVABLE”

color=blue

OR[/color] type

color=blue

of it[/color] = “DRIVE_CDROM”) and (

color=blue

exists[/color] file system type

color=blue

of it[/color]))

color=red

T:[/color] 1099.433 ms

color=red

I:[/color] plural string

Not sure of slick way to exclude the jump drive from showing up.

no easy BBCode color insert pallet :frowning:

(imported comment written by BenKus)

Hey Rad,

You can accomplish everything you want in the relevance language today. Whenever you see the error “Singular expression referes to non-unique object.”, it means you need to add an “s” somewhere to make a plural value. In this case, use “selects”.

This answers your questions about concatenating the drives and searching the returned types:

q: concatenation ", " of (string values of selects “DeviceID from Win32_LogicalDisk” of wmi)

A: C:, D:, K:, M:, N:, O:, P:, Q:

q: exists (types of selects “DeviceID from Win32_LogicalDisk” of wmi) whose (it = 8)

A: True

But for this specific example, please note (as brolly33 showed nicely) that we have a full array of disk inspectors that are far superior to the wmi implementation in many ways.

Ben

(imported comment written by rad.ricka91)

Ben,

thanks, I clearly missed that completely. From the times in Brolly’s post it would seem like the query ultimately ends up in WMI anyway?

R.

(imported comment written by BenKus)

Hey Rad,

I believe the slowness is related to the fact that queries to the disk devices are always fairly slow.

With very few exceptions, all of our inspectors use direct API calls and we avoid the WMI whenever possible.

Ben

(imported comment written by brolly3391)

Rad,

query your fixed drives instead using the same relevance properties and watch how the time drops.

q: names of drives whose ((type of it = “DRIVE_FIXED”) and (exists file system type of it))

A: C:

T: 0.608 ms

I: plural string

Brolly