Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WMI: start process on remote machine with local account on that machine

450 views
Skip to first unread message

Sofia

unread,
Mar 14, 2007, 7:15:20 AM3/14/07
to
Hi! :)

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


Sofia

unread,
Mar 14, 2007, 8:15:27 AM3/14/07
to
I just got a little bit further with this. I tested with my domain admin
account without mentioning the domain and it went past the ConnectServer
row. I then realised I forgot adding ":Win32_Process" to the namespace. I
added it but the script still stops on the .Create row.

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

Sofia

unread,
Mar 14, 2007, 8:26:35 AM3/14/07
to
Ok, I've got it now. As I suspected the wrong object type was returned from
the ConnectServer function. Isn't there any good documentation on these
functions somewhere?

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

Sofia

unread,
Mar 14, 2007, 10:34:34 AM3/14/07
to
I found a page with documentation:

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

Cary Shultz

unread,
Mar 17, 2007, 8:18:33 AM3/17/07
to
Sofia,

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

Rudif

unread,
May 8, 2007, 11:58:01 AM5/8/07
to

"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

0 new messages