break on
$USAGE = 'kix32 rpcstat [$start=y] [$stop=y] [$out=filename]'
;=============================================================
; KIXRPC REMOTE SERVICE STATUS
;
; Requires Windows 2000 ( or Windows NT /w ADSI installed )
; Requires Domain Admin rights
;
; ABSTRACT:
;
; Scans a list of remote servers and queries the status
; of the KXRPC service.
;
; Optionally - gives one the ability to automatically start
; and stop all KXRPC services ...
;
; examples...
;
; kix32 rpcstat ; just query the status
; kix32 rpcstat $out=del.me ; query the status and pipe to file
; kix32 rpcstat $start=y ; query status and restart any stopped
; kix32 rpcstat $stop=y ; query the status and stop any running
;
;=============================================================
; Change this string table to include your servers ...
$SERVERS = "
DN1CMP
DN1CNT
DN1COV
"
$DELIM = chr(10)
$SERVICE_NAME = "KXRPC"
; ADSI service state codes ...
DIM $STATE[9]
$STATE[0] = "UNKNOWN"
$STATE[1] = "STOPPED"
$STATE[2] = "START_PENDING"
$STATE[3] = "STOP_PENDING"
$STATE[4] = "RUNNING"
$STATE[5] = "CONTINUE_PENDING"
$STATE[6] = "PAUSE_PENDING"
$STATE[7] = "PAUSED"
$STATE[8] = "ERROR"
; Redirect output to a file or device ...
if $out
del "$out"
$= redirectoutput ( "$out" )
endif
; Process the command line switches ...
if $start
$start = ucase ( ltrim ( $start ) )
else
$start = "N"
endif
if $stop
$stop = ucase ( ltrim ( $stop ) )
else
$stop = "N"
endif
; Loop for all servers in the list ...
while $servers
; Parse out the server name
$server = substr ( $servers, 1, instr( $servers, "$DELIM" )-len($DELIM))
; Clean it up ...
$server = ucase ( ltrim ( $server ) )
; If a server specified (ie. not a blank line in the list) ...
if $server
; Build the ADSI path to the server service ...
$adspath = "WinNT://$server/$SERVICE_NAME"
; Get the service object from ADSI ...
$service = olegetobject ( 0, "$adspath" )
if @error = 0
; Get the service state (ie, running,stopped) ...
$status = val ( olegetproperty ( $service, "status" ) )
; Check the status so it doesn't blow our state array ...
; Otherwise - get the textual representation of the state ...
if $status < 1 or $status > 8
$service_state = $STATE[0]
else
$service_state = $STATE[$status]
endif
; Report it ...
?"$server: $SERVICE_NAME IS $service_state."
if $service_state = "STOPPED" and $start = "Y"
" STARTING ..."
$= olecallfunc ( $service, "start" )
endif
if $service_state = "RUNNING" and $stop = "Y"
" STOPPING ..."
$= olecallfunc ( $service, "stop" )
endif
else
; Report an error ...
?"$server: @serror"
endif
endif
; Release the object from memory ...
$= olereleaseobject ( $service )
$servers = substr ( $servers, instr( $servers, "$DELIM" )+len($DELIM), len($servers))
loop
?
;======
:finish
;======
if $service
$= olereleaseobject ( $service )
endif
exit