vbscript permission denied: getobject

5.6k views Asked by At

I'm trying to execute a batch file which is located in a server from a vbscript in my local system.

Below code throws permission denied while accessing GETOBJECT

strDomain = "SBICAD"
strComputer = "10.29.83.22"
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer, _
"root\cimv2", _
 "ec12345", _
"sorry@1", _
 "MS_409", _
 "ntlmdomain:" + strDomain)

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



result = objWMIService.Create("C:\script\checkremote.bat", Null, Null,process)


Msgbox result 
WScript.Quit

Is there anyway to pass my server login credentials on GetObject?

Note: The user ec12345 has admin rights.

1

There are 1 answers

7
RRUZ On

You don't need use the GetObject method because you are already connected with the ConnectServer function. So you only must use the ExecQuery method which will be executed using the same connection.

Set objWMIService = objSWbemServices.ExecQuery("Select * From Win32_Process")