Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WMI method for single property

49 views
Skip to first unread message

augustus

unread,
Jun 8, 2007, 12:41:03 AM6/8/07
to
Hi all,

Could someone tell me, is there a way to directly retrieve 1 property from a
namespace, e.g., i want "IdentifyingNumber" from
"Win32_ComputerSystemProduct".
So far, all the code example I found on the internet always return a
collection then I would need to do a "For Each"
[
Set colSWbemObjectSet =
objSWbemServices.InstancesOf("Win32_ComputerSystemProduct")
For Each objSWbemObject In colSWbemObjectSet
fDellServiceTag2 = objSWbemObject.IdentifyingNumber
Next
]

Thanks.

Jeffery Hicks

unread,
Jun 8, 2007, 7:03:24 AM6/8/07
to

WMI queries always return a collection, even if it is only 1 instance.
The code you're finding is what you need to use. You have to enumerate
the collection to get your properties.

--
Jeffery Hicks
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com
VBScript & Windows PowerShell Training -
www.ScriptingTraining.com/classes.asp
Windows PowerShell? - www.SAPIENPress.com/powershell.asp

blog: http://blog.SAPIEN.com
blog: http://jdhitsolutions.blogspot.com

augustus

unread,
Jun 8, 2007, 10:46:01 AM6/8/07
to

"Jeffery Hicks" wrote:

As a side note, wouldn't made sense to have method that retrieve only 1
instance??? I understand that I could use
SWbemServices.ExecQuery("SELECT IdentifyingNumber FROM
Win32_ComputerSystemProduct") so that it would shorten the time for code
execution (I need to retrieve info from about 10 different namespace on about
100 computers), I'm someone who is used to VBA, therefore the WMI query
method doesn't seems very efficient to me....

Jeffery, if you are still reading this, could you give me a brief
explanation to SWbemServices.Get, I thought that it can retrieve a singleton
object, so I tried (guess) the following :

Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer,
"root\cimv2:Win32_ComputerSystemProduct")
Set obj = objSWbemServices.Properties_.Item("IdentifyingNumber").Value

which doesn't work... Is "Properties_" and "Item" is more for newly created
WMI object?

Thanks

urkec

unread,
Jun 8, 2007, 11:31:02 AM6/8/07
to
"augustus" wrote:

> Hi all,
>
> Could someone tell me, is there a way to directly retrieve 1 property from a
> namespace

You can try something like this:


strComputer = "."

Set objWMI = GetObject("winmgmts:\\" & _
strComputer & "\root\cimv2")

Set objProperty = objWMI.Get _
("CIM_DataFile.Name='C:\test.txt'") _
.Properties_ ("Drive")

WScript.Echo objProperty.Name & _
vbTab & objProperty.Value


--
urkec

0 new messages