0

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.

user3186990
  • 21
  • 3
  • 5

1 Answers1

2

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")
RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • But I couldn't create process using objSWbemServices. My target is to make this "objWMIService.Create("C:\script\checkremote.bat", Null, Null,process)" work. – user3186990 Jan 30 '14 at 01:40
  • Error permission denied : GetObject – user3186990 Jan 30 '14 at 06:50
  • 1
    @user3186990 You were already told to not use `GetObject`. What error do you get when you instantiate `objWMIService` the way @RRUZ suggested? Note that `ExecQuery` returns a collection, so it'd be better to use `Set objWMIService = objSWbemServices.Get("Win32_Process")`. – Ansgar Wiechers Jan 30 '14 at 11:26
  • Im new to vbscript.. Actually im looking run a script that is located in remote server. I tried with code posted and got permission denied error. Please suggest how can i do that. – user3186990 Jan 30 '14 at 12:36
  • @user3186990 Please update your question with your modified code and the exact error message. – Ansgar Wiechers Jan 30 '14 at 20:24
  • Im trying with posted code to execute a batch script located in remote server. It throws permission denied: getobject. Please suggest or modify my script to successfully execute the batch file on remote server. – user3186990 Jan 31 '14 at 01:27
  • 1
    @user3186990 For the third time: **DO NOT USE `GetObject`.** It doesn't work the way you seem to think. Please follow the advice you're given. – Ansgar Wiechers Jan 31 '14 at 10:31