WMI Invalid Namespace Error
Can anyone tell me what is wrong with the block of code below:
Code:
Private Sub GetPCInfo(ByVal PCName As String)
Dim queryOS As New SelectQuery("Win32_OperatingSystem")
Dim queryCS As New SelectQuery("Win32_ComputerSystem")
Dim myConnectionOptions As New System.Management.ConnectionOptions
With myConnectionOptions
.Impersonation = System.Management.ImpersonationLevel.Impersonate
'* Use next line for XP
.Authentication = System.Management.AuthenticationLevel.Packet
'* Use next line for Win prior XP
'*.Authentication = System.Management.AuthenticationLevel.Connect
End With
Dim oScope As New ManagementScope("\\" & PCName & "\root\cmvi2", myConnectionOptions)
Dim searchOS As New ManagementObjectSearcher(oScope, queryOS)
Dim searchCS As New ManagementObjectSearcher(oScope, queryCS)
Dim info As ManagementObject
oScope.Connect()
If oScope.IsConnected = False Then
lblStatus.Text = "You are not connected to the remote computer...please try again."
Exit Sub
End If
For Each info In searchOS.Get()
lblOSNameValue.Text = info("name")
lblMachineNameValue.Text = info("csname")
Next
For Each info In searchCS.Get()
lblMemoryValue.Text = info("totalphysicalmemory")
lblManufacturerValue.Text = info("manufacturer")
lblServerTypeValue.Text = info("systemtype")
lblServerModelValue.Text = info("model")
Next
End Sub
I keep getting an invalid namespace error and I don't have the foggiest idea why. Any help would be appreciated.
Thanks,
Jim P.
Re: WMI Invalid Namespace Error
What line is the error on?
Re: WMI Invalid Namespace Error
Try changing
"\root\cmvi2"
to
"\\root\\cmvi2"
Re: WMI Invalid Namespace Error
mendak,
I tried your suggestion but I got an invalid parameter error...robdog888, the line that is erroring out is the oScope.Connect() line. It just says "Invalid namespace"...could this be a permissions issue?
Jim P.
Re: WMI Invalid Namespace Error
Here is some code that someone posted on another forum to the same question...not really sure why there's works and mine doesn't, but hey, if it works, who cares, right?
Code:
Dim PCName As String
PCName = "JPILLER"
Dim msc As ManagementScope = New ManagementScope("\\" & PCName & "\root\cimv2")
Dim query_command As String = "SELECT * FROM Win32_OperatingSystem"
Dim select_query As SelectQuery = New SelectQuery(query_command)
Dim Srch As New ManagementObjectSearcher(msc, select_query)
Dim objMgmt As ManagementObject
For Each objMgmt In Srch.Get
MsgBox(objMgmt("name").ToString())
MsgBox(objMgmt("version").ToString())
MsgBox(objMgmt("csname").ToString())
MsgBox(objMgmt("windowsdirectory").ToString())
Next
Re: WMI Invalid Namespace Error
It seems the difference is that you attempted to .Connect() while they performed the search directly. I only skimmed your code so I may have missed any other information. I also cannot tell why this particular sample works, but then again, this does sort of delve into a Death Valley type territory, WMI that is.