Is it possible to start a process on a remote machine using a local account
on that machine?
If so, how do I do it? What's wrong with my test script?
My test below returns "SWbemLocator: Access is denied." on the
ConnectServer() row.
I have always used my domain admin account to impersonate previouslly so
I've never needed to do this but now a licence is tied to the local
account...
Thanks a million! :)
/Sofia
---------------------------------------------------------------
VBScript:
Option Explicit
'WMI constants
Const wbemImpersonationLevelImpersonate = 3
Const wbemAuthenticationLevelPktPrivacy = 6
'The computer to run on
Dim strComputer : strComputer = "computername" 'my 2003 SP1 server
'The program/command to run
Dim strProgram : strProgram = "notepad.exe"
'Use this account and password
Dim strUserName
strUserName = "username" 'local user account (member of local administrators
group)
'strUserName = Chr(34)+"computername\account"+Chr(34) 'also tested
Dim strPassword : strPassword = "Visma06"
'Connect to WMI (root\cimv2) on Remote machine using specified credentials
Dim objLocator, objWMIService
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objLocator.ConnectServer(strComputer, "root\cimv2",
strUserName, strPassword)
objWMIService.Security_.ImpersonationLevel =
wbemImpersonationLevelImpersonate
objWMIService.Security_.AuthenticationLevel =
wbemAuthenticationLevelPktPrivacy
'Create the process
Dim errReturn, intProcessID
errReturn = objWMIService.Create(strProgram, null, null, intProcessID)
'Check for errors
If errReturn = 0 Then
Wscript.Echo strProgram+" was started with a process ID of
"+CStr(intProcessID)+"."
Else
Wscript.Echo strProgram+" could not be started due to error
"+CStr(errReturn)+"."
End If
I have run this previouslly without problems:
Set objWMIService =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+strComputer+"\root\cimv2:Win32_Process")
errReturn = objWMIService.Create(strProgram, null, null, intProcessID)
I'm currently using:
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objLocator.ConnectServer(strComputer,
"root\cimv2:Win32_Process", strUserName, strPassword)
...
errReturn = objWMIService.Create(strProgram, null, null, intProcessID)
Are the objects called "objWMIService" in the two examples different?
Thanks again! :)
/Sofia
"Sofia" <.> wrote in message news:ODxAPoiZ...@TK2MSFTNGP02.phx.gbl...
If someone else's got the same problem:
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objLocator.ConnectServer(strComputer,
"root\cimv2:Win32_Process", strUserName, strPassword)
objWMIService.Security_.ImpersonationLevel =
wbemImpersonationLevelImpersonate
objWMIService.Security_.AuthenticationLevel =
wbemAuthenticationLevelPktPrivacy
Dim objProcess : Set objProcess = objWMIService.Get("Win32_Process")
Dim errReturn, intProcessID
'errReturn = objWMIService.Create(strProgram, null, Null, intProcessID)
errReturn = objProcess.Create(strProgram, null, Null, intProcessID)
Thanks! :)
/Sofia
"Sofia" <.> wrote in message news:uFkm2JjZ...@TK2MSFTNGP03.phx.gbl...
SWbemLocator.ConnectServer method:
http://msdn2.microsoft.com/en-us/library/aa393720.aspx
SWbemServices object (the returned object):
http://msdn2.microsoft.com/en-us/library/aa393854.aspx
Sorry for spamming!! :)
/Sofia
"Sofia" <.> wrote in message news:eJktDQj...@TK2MSFTNGP06.phx.gbl...
I do not spend too much time in this NG, but do spend time in others.
Thank you for providing all of the details (and answers to your own
questions). You can be sure that there are others with the same - or
similar - questions/issues.
--
Cary W. Shultz
Roanoke, VA 24012
"Sofia" <.> wrote in message news:ODxAPoiZ...@TK2MSFTNGP02.phx.gbl...
"Sofia" wrote:
> If someone else's got the same problem:
>
> Set objLocator = CreateObject("WbemScripting.SWbemLocator")
> Set objWMIService = objLocator.ConnectServer(strComputer,
> "root\cimv2:Win32_Process", strUserName, strPassword)
First : are you sure that you need "Win32_Process" in
"root\cimv2:Win32_Process" ?
It seems superfluous : for me, a script similar to yours also works with
"root\cimv2".
Second : is the created notepad visible in your experiment ?
In my case, I see a notepad.exe process in TaskManager, but it remains
invisible, even if I add
Const SW_NORMAL = 5
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = SW_NORMAL
intReturn = objProcess.Create(strCommand, Null, objConfig, intProcessID)
Any comments or ideas ?
Rudif