I wanted to be able to do certain things during logon, but with programs starting up from the runservices location in registry, I was constantly colliding with the programs I was trying to update. In response to this, I set out to find a solution using TLIST.EXE and KILL.EXE from the Windows resource kit (98 resource kit).

First, here is the batchfile that is shelled by search_proc. In your main script setup a variable like:

$tlist_bat = @LSERVER + "netlogon\bin\tlist.exe"

(or wherever you stick the exe)

then copy this batchfile to the same directory as the exe tlist.exe

@LSERVER\netlogon\bin\TLIST.BAT
~~~~~~~~~~~~~~~~~~~~~~
@echo off
\\%lserver%\netlogon\bin\9x\tlist > c:\~tlist.txt

okay next you take this piece of code and either copy it into your main script or you can save it as an external script and make call statements to it after setting global variables (emulated function sends and returns) The advantage to leaving it outside your main script is that you can then call it from any script you've written. Taking it further, you can define in your environment variables a pre-defined location for your "library functions". Here is an example of calling the function from script (this example is taken from my script which updates Viruscan using the superdat files):

; Make sure the process has finished starting up before running the update
; ---------------------------------------
$search_time = 8
$search_proc = "VSHWIN32.EXE"
$call = $lib_dir + "\" + "search_proc"
call $call
; ---------------------------------------

Ok, now here's the code for the function search_proc (sorry the formatting gets toasted):

;-----------------------------------------------------------------
; SUBROUTINE: search_proc
; AUTHOR: Kevin Torkelson ~ kevin@providentfunding.com
;
; DESCRIPTION:
; Searches for the instance of a named process for a specified duration of time
; and immediately returns upon finding the target. If $search_time is not
; specified, it will look only once.
;
; INPUT:
; $search_proc = The name of the process to look for
; $search_time = The number of seconds to continue searching for the process
; $tlist_bat = The full path to a batchfile which calls TLIST.EXE
;
; OUTPUT:
; $search_rtn = 0 (Process found)
; $search_rtn = 1 (No process by that name was found)
; $search_rtn = 2 (Subroutine failed, unable to obtain list of processes)
;-----------------------------------------------------------------
:search_proc

; /* Exit if this is a Windows NT system */
If @INWIN = 1
? "Warning: lib function search_proc is only designed to run on 9x systems"
Return
Endif

DIM x
DIM cmd
DIM rtn
DIM rtn2
$search_rtn = ""

$time_1 = "@time" ; Parameter for sub calc_time

? "Scanning for process: " $search_proc
:loop

; /* create the process list via batchfile which traps the output of tlist.exe */
$cmd = $tlist_bat
shell $cmd

; /* scan the list of processes */
$rtn = Open(1, "c:\~tlist.txt")
If $rtn = 0
$x = ReadLine(1)
WHILE @ERROR = 0
$rtn2 = instr($x, $search_proc)
If $rtn2 = 0
; /* string was not found */
Else
; /* calculate the current number of seconds */
;----------------------------------------------------->>
$time_2 = "@time" ; Parameter for sub calc_time
gosub "calc_time" ; Returns $time_rtn
;----------------------------------------------------->>
? "Found process: [" + $x + "] ($time_rtn)sec"
$search_rtn = 0
$search_time = ""
$rtn = Close (1)
del "c:\~tlist.txt"
Return
Endif
$x = ReadLine(1)
LOOP
$rtn = Close (1)
Else
? "Warning: search_proc cannot read process list file c:\~tlist.txt"
? "@SERROR"
$search_rtn = 2
$continue = 1
Return
Endif

$time_2 = "@time" ; /* Parameter for sub calc_time */
gosub "calc_time" ; /* Returns $time_rtn */
If ($search_time <> "") and ($time_rtn < $search_time)
goto "loop"
Endif
? "Process not found: " + $search_proc + "(" + $search_time + ")sec"
$search_rtn = 1
$search_time = ""
sleep 1
del "c:\~tlist.txt"
$continue = 1
Return


;-----------------------------------------------------------------
; SUBROUTINE: calc_time
; AUTHOR: (Ripped from the bulletin board of kixtart.to)
; I modified it to always return a positive value in seconds
;
; DESCRIPTION:
; Calculates the difference in seconds between two times in @time format
; Always returns a positive result or 0
;
; INPUT:
; $time_1 = The starting time
; $time_2 = The ending time
;
; OUTPUT:
; $time_rtn = The difference between $time_1 and $time_2 in seconds
;-----------------------------------------------------------------
:calc_time

If ($time_1 <> "") and ($time_2 <> "")

$foo = SUBSTR($time_2,1,2)
$foo = $foo + SUBSTR($time_2,4,2)
$foo = $foo + SUBSTR($time_2,7,2)
$tmp_end = $foo

$foo = SUBSTR($time_1,1,2)
$foo = $foo + SUBSTR($time_1,4,2)
$foo = $foo + SUBSTR($time_1,7,2)
$tmp_start = $foo

$time_rtn = VAL($tmp_end) - VAL($tmp_start)
If ($time_rtn < 0)
$time_rtn = VAL($tmp_start) - VAL($tmp_end)
Endif
Else
? "[Warning: calc_time requires two time variables $time_1 and $time_2]"
$time_rtn = ""
Endif
Return


~~~~~~~~
Now here's another one for killing a process.... set up kill.exe in a similar fashion to tlist.exe (I leave the organization of your binaries up to you guys to figure out :p)

;-----------------------------------------------------------------
; SUBROUTINE: kill_proc
; AUTHOR: Kevin Torkelson ~ kevin@providentfunding.com
;
; DESCRIPTION:
; Runs TLIST.EXE on the 9x host to determine a list of processes running,
; then look for ocurrances of a particular process name. If found,
; kill the first ocurrance of the named process using KILL.EXE
;
; INPUT:
; $kill_proc = The name of the process to kill
; $tlist_bat = The full path to a batchfile which calls TLIST.EXE
; $kill_local = The full path and filename for the executable KILL.EXE
;
; OUTPUT:
; $kill_rtn = 0 (Process killed)
; $kill_rtn = 1 (No process by that name was found)
; $kill_rtn = 2 (Subroutine failed, unable to obtain list of processes)
;-----------------------------------------------------------------
:kill_proc

; /* Exit if this is a Windows NT system */
If @INWIN = 1
? "Warning: lib function search_proc is only designed to run on 9x systems"
Return
Endif


DIM x
DIM cmd
DIM rtn
DIM rtn2
$kill_rtn = ""

? "Scanning for process: " $kill_proc

; /* create the list of processes */
$cmd = $tlist_bat
shell $cmd

; /* scan the list of processes */
$rtn = Open(1, "c:\~tlist.txt")
If $rtn = 0
$x = ReadLine(1)
WHILE @ERROR = 0
$rtn2 = instr($x, $kill_proc)
If $rtn2 = 0
; string was not found
Else
? "Found process: [" + $x + "]"
? "Killing process: " $kill_proc
; /* Currently, output from kill.exe is not trapped */
$cmd = $kill_local + " /f " + $kill_proc
shell $cmd
$kill_rtn = 0
$rtn = Close (1)
del "c:\~tlist.txt"
Return
Endif
$x = ReadLine(1)
LOOP
$rtn = Close (1)
del "c:\~tlist.txt"
else
? "Warning: kill_proc cannot read process list file c:\~tlist.txt"
? "@SERROR"
$kill_rtn = 2
Return
Endif
$kill_rtn = 1
Return


~~~~~~~
Comments welcomed.


------------------
K Torkelson
Sys Admin Analyst
ktorkelson@providentfunding.com