Results 1 to 6 of 6

Thread: WMI Invalid Namespace Error

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    Cleveland, Ohio
    Posts
    185

    Question 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--

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: WMI Invalid Namespace Error

    Try changing

    "\root\cmvi2"

    to

    "\\root\\cmvi2"

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    Cleveland, Ohio
    Posts
    185

    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--

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    Cleveland, Ohio
    Posts
    185

    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--

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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
  •  



Click Here to Expand Forum to Full Width