Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WMI without ManagementObjectSearcher 1

Status
Not open for further replies.

SQLScholar

Programmer
Aug 21, 2002
2,127
GB
hey all,

I know its possible in VBS but i want to do the same in vb.net (so no need for .net).

Code:
        Dim objWMIService
        Dim colItems
        Dim objItem

        Try
            objWMIService = GetObject("winmgmts:\\" & Environ("COMPUTERNAME") & "\root\CIMV2")
            colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

            For Each objItem In colItems
                ComputerName = objItem.Name.ToString
            Next
[code]

Now it errors on For Each objItem In colItems with an Unspecified error on the COM object.  Now I have taken this from VBS and trying to implement it the same way.  What am i doing wrong?

The VBS that works looks something like this

[code
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
arrComputers = Array("localhost")
For Each strComputer In arrComputers
   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
   For Each objItem In colItems
      WScript.Echo "PC_Name," & objItem.Name
      WScript.Echo "Domain," & objItem.Domain
      WScript.Echo "PC_Manufacturer," & objItem.Manufacturer
      WScript.Echo "PC_Model," & objItem.Model
      WScript.Echo "PC_Mem," & objItem.TotalPhysicalMemory
   Next

/SNIP

Any ideas how i can do this?

Dan

----------------------------------------
Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Dr. Seuss

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------
 
Thanks :)

----------------------------------------
Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Dr. Seuss

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top