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.
You don't need use the
GetObject
method because you are already connected with theConnectServer
function. So you only must use theExecQuery
method which will be executed using the same connection.