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

execute process

27 views
Skip to first unread message

Lynn

unread,
Mar 5, 2006, 1:45:24 AM3/5/06
to
Hi,
does anyone have the vb.net code to launch a process on a remote system
using a different username and password?
thanks


Lynn

unread,
Mar 6, 2006, 6:58:44 AM3/6/06
to
Hi,
does anyone have the code to launch a process on a remote system using a

different username and password?
thanks

"Lynn" <Marr...@yah00.c0m> wrote in message
news:eprjCACQ...@TK2MSFTNGP14.phx.gbl...

Jason Gurtz

unread,
Mar 7, 2006, 9:47:05 AM3/7/06
to
Lynn wrote:
> does anyone have the code to launch a process on a remote system using a
> different username and password?

Using the system or run function and psexec program might be a workaround.

~Jason

--

rodionos

unread,
Mar 7, 2006, 2:19:48 PM3/7/06
to
Save this as proc.vbs and run

'cscript proc.vbs "mkdir ''MyDir''" "C:\Program Files"
'cscript proc.vbs "notepad.exe" "C:\Program Files"
strCommand = WScript.Arguments.item(0)
strWorkingDirectory = WScript.Arguments.item(1)
strHost = "."
Set stdout = WScript.StdOut

Set objService =
GetObject("winmgmts:{impersonationLevel=impersonate,(Security)}!\\" &
strHost & "\root\cimv2")
Set objStartup = objService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = SHOW_WINDOW

'prepend with launcher and replace doubled single quote '' with a
double quote "
strCmd = "cmd /c " & Replace(strCommand,"''","""")
stdout.writeLine strCmd
stdout.writeLine strWorkingDirectory

Set objProcess = objService.Get("Win32_Process")
intReturn = objProcess.Create(strCmd, strWorkingDirectory, objConfig,
intProcessID)
IF intReturn <> 0 THEN
stdout.writeLine "Process could not be created." & vbNewLine &
"Command line: " & strCommand & vbNewLine & "Return value: " &
intReturn
ELSE
stdout.writeLine "Process created." & vbNewLine & "Command line: "
& strCommand & vbNewLine & "Process ID: " & intProcessID
END IF

'0 Successful completion
'2 Access denied
'3 Insufficient privilege
'8 Unknown failure
'9 Path not found
'21 Invalid parameter

Lynn

unread,
Mar 8, 2006, 11:13:08 AM3/8/06
to
thanks for the code but this does not seems to execute the remote process
using different username and password?
also how do it know if the remote program has finished executing?

"rodionos" <rodi...@gmail.com> wrote in message
news:1141759188.2...@i39g2000cwa.googlegroups.com...

rodionos

unread,
Mar 8, 2006, 12:47:00 PM3/8/06
to
Hi the code above works in a domain environment. But if you need to
execute it under different account context:

Replace

Set objService =
GetObject("winmgmts:{impersonationLevel=impersonate,(Security)}!\\" &
strHost & "\root\cimv2")

With

Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objService = objLocator.ConnectServer(host,namespace,user,pwd)

rodionos

unread,
Mar 8, 2006, 12:52:37 PM3/8/06
to
As for identifying when the launched process has terminated, you can
either poll the same WMI class with WHERE clause using pid which you
could obtain at start-up time using the code I posted earlier.
Alternatively you can execute an asynch. query which will notify your
listener/consumer once the process is terminated (the instance is
removed).

0 new messages