|
-
Mar 23rd, 2007, 03:00 PM
#1
Thread Starter
Addicted Member
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.
"The Force will be with you, always."
--Ben Kenobi--
-
Mar 23rd, 2007, 04:46 PM
#2
Re: WMI Invalid Namespace Error
What line is the error on?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 25th, 2007, 06:34 AM
#3
Re: WMI Invalid Namespace Error
Try changing
"\root\cmvi2"
to
"\\root\\cmvi2"
-
Mar 26th, 2007, 10:25 AM
#4
Thread Starter
Addicted Member
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.
Last edited by jpiller; Mar 26th, 2007 at 10:44 AM.
"The Force will be with you, always."
--Ben Kenobi--
-
Mar 27th, 2007, 08:26 AM
#5
Thread Starter
Addicted Member
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
"The Force will be with you, always."
--Ben Kenobi--
-
Mar 27th, 2007, 01:56 PM
#6
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|