#72880 - 2003-02-05 10:04 PM
Running a script as a service error...
|
whaler
Fresh Scripter
Registered: 2002-11-27
Posts: 20
Loc: Mississauga, Canada
|
I have a kix script installed as a service on a server that is started by a remote user using the "sc.exe" command. The user is connected to the box as an admin, required to be able to start the service, and the service is configured to run as the local administrator.
When I run the script on the box, locally, everything works fine and as expected. When executed as a "service" the script terminates bad, as it leaves "excel.exe" running, as seen in the Task Manager, and the value of $huh seems to be 2 as it always copies out the little text message.
$name.txt is a file created by the client on the local server with a server name.
$open.txt is a "control" file that I use. I have about 9 different versions of this for checking our various environments. This way only one can be run at a time.
code:
SLEEP 20 IF EXIST ("d:\nowmi\open.txt") <> 0 DEL ("d:\nowmi\name.txt") EXIT ENDIF
$NULL = OPEN (1,"d:\nowmi\open.txt",5) $NULL = CLOSE (1)
$NULL = OPEN (1,"d:\nowmi\name.txt",2) IF @ERROR <> 0 $NULL = CLOSE (1) DEL ("d:\nowmi\name.txt") EXIT ENDIF $Name = READLINE (1) $NULL = CLOSE (1) DEL ("d:\nowmi\name.txt") $UName = UCASE("$Name")
$COMPUTER = "navacbzw1" $PROC = "excel.exe"
ENDPROC($COMPUTER,$PROC)
FUNCTION ENDPROC($COMPUTER,$PROC) For each $Process in GetObject("winmgmts:{impersonationLevel=impersonate}!//$COMPUTER").ExecQuery("select * from Win32_Process where Name='$PROC'") $ = $Process.Terminate Next ENDFUNCTION
$cfilename = "d:\security\servers.xls" READEXCEL($cfilename)
FUNCTION READEXCEL($cfilename) IF $cfilename = "" GOTO END ; -- Excel file not found" ENDIF $oxl = Createobject("Excel.application") $rc = $oxl.workbooks.open($cfilename) $nrow = 1 $huh = 2 WHILE $oxl.cells($nrow, 1).value <> "" $nrow = $nrow + 1 IF $oxl.cells($nrow, 4).value = "" $oxl.quit $oxl = "" RETURN ENDIF $value1 = $oxl.cells($nrow, 4).value ; -- Get the Hostname $Uvalue1 = UCASE("$value1") IF $UValue1 = $UName $value0 = $oxl.cells($nrow, 6).value ; -- Get the Environment Name $value2 = $oxl.cells($nrow, 7).value ; -- Get the UserID $value3 = $oxl.cells($nrow, 8).value ; -- Get the Password $value4 = $oxl.cells($nrow, 5).value ; -- Get the IP Address USE "\\$Value4\ipc$" /user:$value2 /password:$value3 IF @ERROR = 0 $NULL = OPEN (1,"d:\HFNetCHK\hostfile.txt",5) $NULL = WRITELINE (1,"$Value4"+@CRLF) $NULL = CLOSE (1) $huh = 1 ELSE $NULL = OPEN (1,"d:\HFNetCHK\noonemap.txt",5) $NULL = WRITELINE (1,"Unable to map $Value1 in $Value0 on @DATE"+@CRLF) $NULL = CLOSE (1) SHELL 'net use x: \\49.0.0.1\d$ /user:administrator password' COPY "d:\hfnetchk\noonemap.txt" "x:\inetpub\wwwroot\mspatch\noonemap.txt" DEL ("x:\inetpub\wwwroot\mspatch\mapone.txt") $huh = 0 ENDIF ENDIF LOOP $oxl.quit $oxl = "" ENDFUNCTION
SELECT CASE $huh = 1 GOTO Continue CASE $huh = 2 GOTO Nothing CASE $huh = 0 GOTO END ENDSELECT
GOTO END
:Continue
SELECT
CASE $value0 = "PAT" SHELL 'hfnetchk -fip d:\hfnetchk\hostfile.txt -t 5 -s 2 -nosum -o tab -f d:\patchlogging\hfnetchk_PAT.txt' SHELL 'dtsrun /S49.0.0.0 /Usa /Ppassword /NHFNETCHK_PAT_DTS' CASE $value0 = "CPO" SHELL 'hfnetchk -fip d:\hfnetchk\hostfile.txt -t 5 -s 2 -nosum -o tab -f d:\patchlogging\hfnetchk_CPO.txt' SHELL 'dtsrun /S49.0.0.0 /Usa /Ppassword /NHFNETCHK_CPO_DTS' CASE $value0 = "SOC" SHELL 'hfnetchk -fip d:\hfnetchk\hostfile.txt -t 5 -s 2 -nosum -o tab -f d:\patchlogging\hfnetchk_SOC.txt' SHELL 'dtsrun /S49.0.0.0 /Usa /Ppassword /NHFNETCHK_SOC_DTS' CASE $value0 = "TREE" SHELL 'hfnetchk -fip d:\hfnetchk\hostfile.txt -t 5 -s 2 -nosum -o tab -f d:\patchlogging\hfnetchk_TREE.txt' SHELL 'dtsrun /S49.0.0.0 /Usa /Ppassword /NHFNETCHK_TREE_DTS' CASE $value0 = "DEV" SHELL 'hfnetchk -fip d:\hfnetchk\hostfile.txt -t 5 -s 2 -nosum -o tab -f d:\patchlogging\hfnetchk_DEV.txt' SHELL 'dtsrun /S49.0.0.0 /Usa /Ppassword /NHFNETCHK_DEV_DTS' CASE $value0 = "TREB" SHELL 'hfnetchk -fip d:\hfnetchk\hostfile.txt -t 5 -s 2 -nosum -o tab -f d:\patchlogging\hfnetchk_TREB.txt' SHELL 'dtsrun /S49.0.0.0 /Usa /Ppassword /NHFNETCHK_TREB_DTS' ENDSELECT
SHELL 'dtsrun /S49.0.0.0 /Usa /Ppassword /NCMSPATCH1'
SHELL 'net use x: \\49.0.0.1\d$ /user:administrator password' DEL ("x:\inetpub\wwwroot\mspatch\noonemap.txt") COPY "d:\hfnetchk\hostfile.txt" "x:\inetpub\wwwroot\mspatch\mapone.txt" GOTO END
:Nothing SHELL 'net use x: \\49.0.0.1\d$ /user:administrator password' DEL ("x:\inetpub\wwwroot\mspatch\noonemap.txt") $NULL = REDIRECTOUTPUT ("X:\inetpub\wwwroot\mspatch\mapone.txt",1) "For some reason the server name you entered could not be found"+@CRLF "Please check your spelling. If this does not work, please verify"+@CRLF "that the system exists in the security inventory spreadsheet."+@CRLF " "+@CRLF "SERVER NAME ENTERED = $name" $NULL = REDIRECTOUTPUT ("")
:END
SHELL 'net use * /D /y'
DEL ("d:\HFNetCHK\hostfile.txt") DEL ("d:\HFNetCHK\noonemap.txt")
DEL ("d:\hfnetchk\DFSD") DEL ("d:\patchlogging\DFSD") :END DEL ("d:\nowmi\open.txt")
EXIT
Anyone with thoughts or hints... or general code improvements? ![[Smile]](images/icons/smile.gif) [ 06. February 2003, 06:06: Message edited by: whaler ]
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 972 anonymous users online.
|
|
|