Discussion:
WMI: start process on remote machine with local account on that machine
(too old to reply)
Sofia
2007-03-14 11:15:20 UTC
Permalink
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
2007-03-14 12:15:27 UTC
Permalink
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
Post by Sofia
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
---------------------------------------------------------------
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
2007-03-14 12:26:35 UTC
Permalink
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
Post by Sofia
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.
Set objWMIService =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+strComputer+"\root\cimv2:Win32_Process")
errReturn = objWMIService.Create(strProgram, null, null, intProcessID)
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
Post by Sofia
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
---------------------------------------------------------------
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
2007-03-14 14:34:34 UTC
Permalink
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
Post by Sofia
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?
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
Post by Sofia
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.
Set objWMIService =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+strComputer+"\root\cimv2:Win32_Process")
errReturn = objWMIService.Create(strProgram, null, null, intProcessID)
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
Post by Sofia
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
---------------------------------------------------------------
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
Rudif
2007-05-08 15:58:01 UTC
Permalink
Post by Sofia
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

Cary Shultz
2007-03-17 12:18:33 UTC
Permalink
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
Post by Sofia
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
---------------------------------------------------------------
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
Loading...