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)