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

624 views Asked by At

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!

1

There are 1 answers

0
kwirky_penguin On

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