#144630 - 2005-08-02 06:03 PM
create service doesn't return $pid
|
Eduardo
Fresh Scripter
Registered: 2005-01-27
Posts: 5
|
Hi Guys,
I have a little Problem creating a Process with WMI. Sorry not creating but more getting all data from it. Here is a .vbs script that starts Notepad.exe and shows me the PID.
<Code> Const SW_NORMAL = 1 strComputer = "." strCommand = "Notepad.exe"
Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2")
' Configure the Notepad process to show a window Set objStartup = objWMIService.Get("Win32_ProcessStartup") Set objConfig = objStartup.SpawnInstance_ objConfig.ShowWindow = SW_NORMAL
' Create Notepad process Set objProcess = objWMIService.Get("Win32_Process") intReturn = objProcess.Create _ (strCommand, "c:\", Null, intProcessID) If intReturn <> 0 Then Wscript.Echo "Process could not be created." & _ vbNewLine & "Command line: " & strCommand & _ vbNewLine & "Return value: " & intReturn Else Wscript.Echo "Process created." & _ vbNewLine & "Command line: " & strCommand & _ vbNewLine & "Process ID: " & intProcessID End If </code>
And here is the same script I have trying with KiXtart. (Thanks to Radimus, mostly copied his RemoteExec() udf). It can do everything except show me the PID ($ProcessID). What I'm doing wrong. Please help me, then I'm thinking I've overlooked something.
<code> Break On
$nul=SetOption("Explicit","On") $nul=SetOption("WrapAtEOL","On") $nul=SetOption("NovarsinString","On")
Dim $SW_Normal,$computer,$command,$objWMIService,$objStartup Dim $objConfig,$objProcess,$ProcessID,$Return
$SW_Normal = 1 $computer = '.' $command = "Notepad.exe"
$objWMIService = GetObject('winmgmts:{impersonationLevel=impersonate}!//'+$computer+'/root/cimv2')
$objStartup = $objWMIService.Get("Win32_ProcessStartup") $objConfig = $objStartup.SpawnInstance_ $objConfig.ShowWindow = $SW_Normal
$objProcess = $objWMIService.Get("Win32_Process") $Return = $objProcess.Create($command,"c:\",$objconfig ,$ProcessID) if @Error ?"Process could not be created." +@crlf + "command line: " +$command + @crlf+ "Process ID: " + $ProcessID else ?"Process created." +@crlf + "command lin: " +$command + @crlf+ "Process ID: " + $ProcessID endif </code>
Before I post it I found this post But I can't run it. (unexpectet command). example create Service with ProcessID
$command in quotes was a typing error.
Edited by Eduardo (2005-08-02 06:50 PM)
|
|
Top
|
|
|
|
#144633 - 2005-08-02 06:40 PM
Re: create service doesn't return $pid
|
Eduardo
Fresh Scripter
Registered: 2005-01-27
Posts: 5
|
Hi Les,
I'm on it.
Thanks for the advice.
|
|
Top
|
|
|
|
#144635 - 2005-08-02 07:29 PM
Re: create service doesn't return $pid
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
yep... kix will not handle the return of the processid parameter.
You'll need to inventory the processes before and after
see enumprocess() UDF
|
|
Top
|
|
|
|
#144636 - 2005-08-02 09:34 PM
Re: create service doesn't return $pid
|
Eduardo
Fresh Scripter
Registered: 2005-01-27
Posts: 5
|
Thanks for the fast responce. I'll have a look at enumprocess() udf.
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 302 anonymous users online.
|
|
|