By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,603 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,603 IT Pros & Developers. It's quick & easy.

Different between two ways to get WMI

P: n/a
yxq
Hello,
I want to get some system info using WMI class, but there are two ways, i
want to know what different between them, thank you.

The first:
******************************************
Dim info As ManagementObject
Dim search As ManagementObjectSearcher
search = New ManagementObjectSearcher("SELECT * From
Win32_OperatingSystem")
For Each info In search.Get()
Messagebox.Show info("Caption")
Next
The Second:
*******************************************
Public objWMI As Object
Public colItems As Object
Public objItem As Object
objWMI = GetObject("WinMgmts:/root/cimv2")
colItems = objWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem")

For Each objItem In colItems
Messagebox.Show objItem.Caption
Next
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
yxq
Why the first way will not work sometimes, but the second way can?

"yxq" <ga***@163.net> 写入消息新闻:%2****************@tk2msftngp13.phx.g bl...
Hello,
I want to get some system info using WMI class, but there are two ways, i
want to know what different between them, thank you.

The first:
******************************************
Dim info As ManagementObject
Dim search As ManagementObjectSearcher
search = New ManagementObjectSearcher("SELECT * From
Win32_OperatingSystem")
For Each info In search.Get()
Messagebox.Show info("Caption")
Next
The Second:
*******************************************
Public objWMI As Object
Public colItems As Object
Public objItem As Object
objWMI = GetObject("WinMgmts:/root/cimv2")
colItems = objWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem")

For Each objItem In colItems
Messagebox.Show objItem.Caption
Next

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.