Page 1 of 1 1
Topic Options
#151122 - 2005-11-07 10:25 PM FindPROC in Terminal Server
Duvander Offline
Fresh Scripter

Registered: 2005-11-07
Posts: 27
Hi

I'm using following FUNCTION to determine if "notepad.exe" is running and if its not, start "notepad.exe". Problem then running this on terminal server, if another user (in another session) is running notepad.exe it will not start notepad.exe. How can I change so it checks if it is @USERID (current user) that has started notepad.exe?

IF NOT FindPROC("notepad.exe")
RUN "notepad.exe"
ENDIF

FUNCTION FindPROC($PROC,optional $COMPUTER, optional $terminate)
dim $GetObject, $Select
if not $computer $computer=@wksta endif
$GetObject="winmgmts:{impersonationLevel=impersonate}!//$COMPUTER"
$select="select * from Win32_Process where Name='$PROC'"
For each $Process in GetObject("$GetObject").ExecQuery("$select")
if $terminate $Process.Terminate endif
$FindPROC=$Process.Name
Next
ENDFUNCTION

/Stefan Duvander

Top
#151123 - 2005-11-07 10:47 PM Re: FindPROC in Terminal Server
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
see qprocess.exe in XP
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#151124 - 2005-11-08 10:52 PM Re: FindPROC in Terminal Server
Duvander Offline
Fresh Scripter

Registered: 2005-11-07
Posts: 27
Can I use qprocess in a kix-script? How?
I'm not supposed to start notepad, thatīs just an example.
The function is in a much larger kix-script. Can anyone give me an example how to manage this?

/Stefan

Top
#151125 - 2005-11-09 01:03 PM Re: FindPROC in Terminal Server
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
If you have "tasklist", here is an easy way to do it:
Code:
$sProcess="notepad.exe"

Shell '"'+%COMSPEC%+'" /C '
+'tasklist /FI "USERNAME eq '+@USERID
+'" /FI "IMAGENAME eq '+$sProcess+'" /NH | FIND "No tasks" >NUL:'
If @ERROR
"Already running an instance of '"+$sProcess+"'"+@CRLF
Else
"No '"+$sProcess+"' running for this user, so I'll start one now..."+@CRLF
Run $sProcess
EndIf


Top
#151126 - 2005-11-09 06:32 PM Re: FindPROC in Terminal Server
Duvander Offline
Fresh Scripter

Registered: 2005-11-07
Posts: 27
Hi Richard

Haven't met you, but already love you...

Thanks a lot!!!

/Stefan

Top
#151127 - 2005-11-09 10:36 PM Re: FindPROC in Terminal Server
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Hold on there... this is a family board
Top
Page 1 of 1 1


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

Who's Online
0 registered and 765 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.132 seconds in which 0.101 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