none
Connecting to a Remote computer's WMI - Namespace that is different from CIMV2

    Question

  • Hey All,

    im writing a VBscript that should be run remotely with given credentials (as arguments) and monitor IIS through WMI.

    To do this, im using WbemScripting.SwbemLocator.

    When i use it to connect to the "Root\Cimv2" Nameapce, it works just fine:

    strComputer = WScript.Arguments(0)
        strUser = WScript.Arguments(1)
        strPass = WScript.Arguments(2)
        Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
        Set objWMIService = objSWbemLocator.ConnectServer _
            (strComputer, "root\cimv2", strUser, strPass)   

    objSWbemServices.Security_.ImpersonationLevel = 3

       Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_W3SVC_WebService", "WQL", _
                                              wbemFlagReturnImmediately + wbemFlagForwardOnly)

    But when i use exactly the same logic, and exactly the same arguments, but i connect to a namespace that is different then CIMV2, in my case:

    \root\microsoftiisv2 (to monitor IIS)

    i get an access is denied error, on the line that i execute the query (and not on the authentication line):

    strComputer = WScript.Arguments(0)

        strUser = WScript.Arguments(1)
        strPass = WScript.Arguments(2)
        Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
        Set objWMIService = objSWbemLocator.ConnectServer _
            (strComputer, "root\microsoftiisv2", strUser, strPass)
        objSWbemServices.Security_.ImpersonationLevel = 3    
        
    Set colItems = objWMIService.ExecQuery _
        ("Select * From IIsApplicationPool")

    Which means that i am able to connect to the objWMIService, but don't have the access level necessary to perform a query.

    I thought that it might be related to the imeprsonation level, but i changed it and even deleted it and the problem remained the same.

    I guess, for some reason, i might need to do something extra if i want to connect to a namespace that isn't CIMV2.

    Thoughts, anyone?



    • Edited by MOMER Monday, February 27, 2012 2:28 PM
    Monday, February 27, 2012 2:27 PM

Answers

  • objSWbemServices.Security_.AuthenticationLevel = 6 'wbemAuthenticationLevelPkt

    When in doubt go to the instructions on the box.  Sometimes they are actually helpful.

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms695984(v=vs.85).aspx


    ¯\_(ツ)_/¯

    • Marked as answer by MOMER Wednesday, February 29, 2012 11:44 AM
    Monday, February 27, 2012 5:56 PM
  • Thank you very much.

    Setting the Authentication Level to 6 made it work:

     	strUser = WScript.Arguments(1)
    	strPass = WScript.Arguments(2)
    	Const WbemAuthenticationLevelPktPrivacy = 6
    
    	Set Locator = CreateObject("WbemScripting.SWbemLocator")
    	Locator.Security_.AuthenticationLevel = WbemAuthenticationLevelPktPrivacy
    	Set objWMIService = Locator.ConnectServer _
        	(strComputer, "root\microsoftiisv2", strUser, strPass)

    This is the relevant code,

    after this i could succesfully query WMI Classes.

    JRV, i really appreciate your help.

    Sometimes the cynicism isn't in place, i feel.

    This is a help forum, if i knew all that you guys know i wouldn't need help.

    I try to read by myself and do everything i can before i post here - posting here is a last resort...

    Sometimes i miss things, but still, the cynical reaction isn't pleasent.

    If i misunderstood you, i apologize.

    Anyway, i appreciate your help and this worked perfectly,

    Thanks.


    • Marked as answer by MOMER Wednesday, February 29, 2012 11:44 AM
    • Edited by MOMER Wednesday, February 29, 2012 11:50 AM
    Wednesday, February 29, 2012 11:44 AM

All replies

  • I believe you need pachetprivacy as well.

    Set objWMIService = GetObject("winmgmts:
    {authenticationLevel=pktPrivacy}\\" & strComputer & "\root
    \microsoftiisv2")


    ¯\_(ツ)_/¯

    Monday, February 27, 2012 5:04 PM
  • ok, but to use alternate credentials, i can't use the GetObject Method,

    so this doesn't help to solve the issue. How do i use pachetprivacy within WbemScripting.SWbemLocator?

    Monday, February 27, 2012 5:31 PM
  • objSWbemServices.Security_.AuthenticationLevel = 6 'wbemAuthenticationLevelPkt

    When in doubt go to the instructions on the box.  Sometimes they are actually helpful.

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms695984(v=vs.85).aspx


    ¯\_(ツ)_/¯

    • Marked as answer by MOMER Wednesday, February 29, 2012 11:44 AM
    Monday, February 27, 2012 5:56 PM
  • Thank you very much.

    Setting the Authentication Level to 6 made it work:

     	strUser = WScript.Arguments(1)
    	strPass = WScript.Arguments(2)
    	Const WbemAuthenticationLevelPktPrivacy = 6
    
    	Set Locator = CreateObject("WbemScripting.SWbemLocator")
    	Locator.Security_.AuthenticationLevel = WbemAuthenticationLevelPktPrivacy
    	Set objWMIService = Locator.ConnectServer _
        	(strComputer, "root\microsoftiisv2", strUser, strPass)

    This is the relevant code,

    after this i could succesfully query WMI Classes.

    JRV, i really appreciate your help.

    Sometimes the cynicism isn't in place, i feel.

    This is a help forum, if i knew all that you guys know i wouldn't need help.

    I try to read by myself and do everything i can before i post here - posting here is a last resort...

    Sometimes i miss things, but still, the cynical reaction isn't pleasent.

    If i misunderstood you, i apologize.

    Anyway, i appreciate your help and this worked perfectly,

    Thanks.


    • Marked as answer by MOMER Wednesday, February 29, 2012 11:44 AM
    • Edited by MOMER Wednesday, February 29, 2012 11:50 AM
    Wednesday, February 29, 2012 11:44 AM
  • Not cynical but a real request given in a way that should be harder to forget.

    If you were to have looked up the usage of teh call on teh MSDN or Technet sites you would have seen this and more.

    I was just trying to remind anyone reading this that looking things up can save a lot of time.

    I ma glad the solution worked.

    Also it is a good idea to read through all of the infomation on use of the SWebmLocator class as it can help you resolve many different issues.  Knowing how to find the docs and what they contain can save time.


    ¯\_(ツ)_/¯

    Wednesday, February 29, 2012 5:22 PM