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