Page 1 of 1 1
Topic Options
#144630 - 2005-08-02 06:03 PM create service doesn't return $pid
Eduardo Offline
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
#144631 - 2005-08-02 06:17 PM Re: create service doesn't return $pid
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Please edit your post to fix the long line. Also, it is KiXtart, NOT KixTart!
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#144632 - 2005-08-02 06:39 PM Re: create service doesn't return $pid
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Why do you wrap $command in quotes?
$Return = $objProcess.Create("$command","c:\",$objconfig ,$ProcessID)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#144633 - 2005-08-02 06:40 PM Re: create service doesn't return $pid
Eduardo Offline
Fresh Scripter

Registered: 2005-01-27
Posts: 5
Hi Les,

I'm on it.

Thanks for the advice.

Top
#144634 - 2005-08-02 07:11 PM Re: create service doesn't return $pid
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I don't believe KiX can return $ProcessID by reference like VBS can. I think your only choice is to query for it separately and if you have multiple instances, it can get tricky.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#144635 - 2005-08-02 07:29 PM Re: create service doesn't return $pid
Radimus Moderator Offline
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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#144636 - 2005-08-02 09:34 PM Re: create service doesn't return $pid
Eduardo Offline
Fresh Scripter

Registered: 2005-01-27
Posts: 5
Thanks for the fast responce. I'll have a look at enumprocess() udf.
Top
#144637 - 2005-08-03 01:52 AM Re: create service doesn't return $pid
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Ja before and after... why did I not think of that?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#144638 - 2005-08-03 01:49 PM Re: create service doesn't return $pid
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
canadian electric winds interrupted your brainwave?
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 302 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.058 seconds in which 0.022 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org