Results of wmi

(imported topic written by cstoneba)

I have 2 wmi queries and I basically want to get the StartingOffset value (#2) for each result of Antecedents (#1). Is that possible?

#1

q: (following text of last “=” of string value of property “Antecedent” of it) of select objects “Antecedent from Win32_LogicalDiskToPartition” of wmi

A: “Disk #0, Partition #0

A: “Disk #1, Partition #0

T: 31.023 ms

#2

Q: string value of select (“StartingOffset from Win32_DiskPartition WHERE DeviceID = ‘Disk #0, Partition #0’”) of WMI

A: 1048576

T: 20.476 ms

Q: string value of select (“StartingOffset from Win32_DiskPartition WHERE DeviceID = ‘Disk #1, Partition #0’”) of WMI

A: 1044955

T: 24.027 ms

(imported comment written by SystemAdmin)

I thought I’d mention one part of my thought process regarding development and testing. As my machine doesn’t have more than one drive (and thus only returns a single entry), I didn’t want to try a solution that wouldn’t handle multiple entries. Therefore, I decided to find a wmi query that would return multiple results and get that working, then proceed to the real solution.

This is working version from my test wmi query:

Q: (following text of first “|UserId#” of it, preceding text of first “|UserId#” of it) of substrings separated by “|FullName#” of following text of first “FullName#” of concatenation “|” of ( (name of it &"#"& string value of it) of selects (“Fullname,UserID from Win32_NetworkLoginProfile where Fullname is not null”) of wmi )

A: 123456, Bob J.

A: 135792, James W.

T: 351.899 ms

I: plural ( substring, substring )

Then I replaced the various pieces, as necessary:

Q: (following text of first “|StartingOffset#” of it, preceding text of first “|StartingOffset#” of it) of substrings separated by “|DeviceID#” of following text of first “DeviceID#” of concatenation “|” of ( (name of it &"#"& string value of it) of selects (“DeviceID, StartingOffset from Win32_DiskPartition”) of wmi )

A: 32256, ( Disk #0, Partition #0 )

T: 30.787 ms

I: plural ( substring, substring )

One thing I noticed when I looked at the two queries initially is that the antecedent string value you’re looking for must exist in the second query (as it is used as a filter). Thus I just used the second query line and modified the query to return both elements.

From that point, I’ve done what I’ve had to do numerous times, which is to add delimiters within the string as ‘section markers’ and then split the string on those parts to get the pairs that I want out of it. Some of the added strings ("#") are just there to help separate the data elements visually while I was testing and can be removed, if preferred.

Also, be aware that if you extract different data elements in the wmi query, the results will come back in alphabetical order, and thus you may have to change how the splitting process handles this.

(Note: depending on why you thought you needed two queries, I realised that it might not quite provide a working solution for you, but hopefully you’ll find it helpful.)

-Jim

(imported comment written by cstoneba)

thanks much!