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:
- Turn off firewall on remote machine.
- Change HKLM\Software\Policies\Microsoft\Windows NT\RPC "RestrictRemoteClients" from 2 to 1 on remote machine
- 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