简体   繁体   中英

VBScript Remote WMI Call "Error:0 'Permission denied: 'GetObject"

I am receiving the following error when trying to do a remote WMI call:

Failed to parse the script. Error: Source:'Microsoft VBScript runtime error' Line 4 Char:1 Error:0 'Permission denied: 'GetObject''

If I run the following code pointing to my local machine, I receive no error. However, when I run the code pointing to a remote machine I get the error above.

strComputer = "COMPUTER-X"
strService = "Netlogon"

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colRunningServices = objWMIService.ExecQuery("Select * from WIN32_Service")

For Each objService in colRunningServices
    if objService.DisplayName = strService then
        if objService.State = "Running" then
            Context.SetValue 1
        else
            Context.SetValue 0
        End If
    Else
    End If
Next

I have tried the following:

  1. Turn off firewall on remote machine.
  2. Change HKLM\Software\Policies\Microsoft\Windows NT\RPC "RestrictRemoteClients" from 2 to 1 on remote machine
  3. Change Group Policy Computer Configuration\Admistrative Templates\System\RPC "Restrict Unauthenticated RPC clients" and "Enable RPC Endpoint Mapper Client Authenticatin" settings.

Any help would be appreciated!

The computer doing the query was connecting to the remote machine with is computer account (CONTOSCO\COMPUTER-X) and it did not have the correct permissions to execute winmgmts commands. After adding the computer account (CONTOSCO\COMPUTER-X) to the local administrators group, the query executed with no issue!

Reference: https://learn.microsoft.com/en-us/windows/win32/wmisdk/user-account-control-and-wmi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM