#37198 - 2003-03-03 01:40 PM
Problems with error messages
|
Jtel
Fresh Scripter
Registered: 2002-04-13
Posts: 41
|
I have a script that does various things and along the way it checks for certain errors or conditions, and if those conditions are met, it sets a variable - $errmsg to something predefined and then sends the script to the END using GOTO and then writes the value of $errmsg to a file on a remote server and exits the script. Everything works fine except for the fact that on some machines it writes the error message 3 times. Any ideas? This is only a portion of the code.
code:
If $spack < 3 $start = @TIME If Exist("f:\EFOupdts\w2k\W2ksp3\i386\update\update.exe") ;check for 'F' drive mapped to local server for source files $check = "ok" Else $errmsg = "Update cannot continue - the F: drive is not present." Goto END EndIf ?"Checking for necessary disk space ..." Sleep 2 If $HDspace < 179200 $errmsg = "Disk space is insufficient for Win2K PRO Service Pack 3 install" ?"Disk space is insufficient - terminating update." Sleep 4 Goto END Else ?"Disk space is sufficient." Sleep 2 Del("c:\efo\"+@WKSTA+".efo") CLS ?" Updates required. Please read message and click on OK." $Inst = MessageBox("Your PC needs to be updated to Windows 2000 Professional Service Pack 3." + " This install will begin when you click the OK button. Depending on your" + " network connection and the speed of your computer, this update can take" + " anywhere from 15 to 45 minutes. Please do not run any programs during this time." + " Your PC will reboot automatically when the update is complete." + Chr(13) + Chr(10) + "" + Chr(13) + Chr(10) + "We apologize for any inconvenience that this may cause you, but this update" + " is necessary to keep your PC in compliance with security standards." + Chr(13) + Chr(10) + "","WFSC System Updates",48) CLS ??"" ?" Initiating install..." ??" Please be patient. DO NOT CANCEL THIS PROCESS!" ?" DOING SO COULD CAUSE YOUR PC TO MALFUNCTION." ??" Your PC will reboot when the update is complete." Shell "%comspec% /c f:\EFOupdts\w2k\W2ksp3\i386\update\update.exe -u -f -n -o -z" If @ERROR = "1603" $RC = MessageBox(@FULLNAME+", please do not cancel the update process. This update" + " is required for your PC to meet security standards. " + Chr(13) + Chr(10) + "" + Chr(13) + Chr(10) + "Please click RETRY to restart the update program. If you choose" + " to click cancel, your user information will be logged. " + Chr(13) + Chr(10) + "You will prompted to perform the update each" + " time you log on." + Chr(13) + Chr(10) + "" + Chr(13) + Chr(10) + "Thank you.","Cancellation Warning",21) If $RC = 4 Shell "%comspec% /c f:\EFOupdts\w2k\W2ksp3\i386\update\update.exe -u -f -n -o -z" If @ERROR = "1603" Shell '%comspec% /c echo @TIME @DATE @USERID @WKSTA - Win2K Service Pack 3' + ' installation began at '+$start+' and was cancelled by the user.' + '>> \\servername\efolan\efoupdts\errors\aborted.err' Goto End EndIf Else Shell '%comspec% /c echo @TIME @DATE @USERID @WKSTA - Win2K Service Pack 3' + ' installation began at '+$start+' and was cancelled by the user.' + '>> \\servername\efolan\efoupdts\errors\aborted.err' Goto END EndIf EndIf CLS ??" Updating the registry ..." $RC = WriteValue("HKEY_LOCAL_MACHINE\Software\EFO\Installed By Script\ServicePacks\SP1","InstallDate","@DATE","Reg_SZ") $RC = WriteValue("HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU","NoAutoUpdate","1","Reg_DWORD") ?" Update complete." $stop = @TIME ??"Updating installation log..." Shell '%comspec% /c echo @TIME @DATE @USERID @WKSTA - Win2K Service Pack 3' + ' installation began at '+$start+' and ended at '+$stop + '>> \\servername\efolan\efoupdts\errors\timelog.err' ??" Initiating system shutdown" Sleep 3 $RC = Shutdown("", "System will now reboot to enable new settings.", 10, 1, 1) EndIf EndIf Goto END ;this is here because there is actually a lot more code before the END label :END If $errmsg <> "" Shell '%comspec% /c echo @TIME @DATE @USERID @FULLNAME @WKSTA - '+$errmsg+'>> \\servername\efolan\efoupdts\errors\errors.err' EndIf Exit
[ 03. March 2003, 16:42: Message edited by: Jtel ]
|
|
Top
|
|
|
|
#37200 - 2003-03-03 01:55 PM
Re: Problems with error messages
|
Jtel
Fresh Scripter
Registered: 2002-04-13
Posts: 41
|
Here's a larger sample of the code where the problem occurs. Like I said, everything works fine - it just sometimes writes $errmsg 3 times.
code:
If $spack < 3 $start = @TIME If Exist("f:\EFOupdts\w2k\W2ksp3\i386\update\update.exe") ;check for 'F' drive mapped to local server for source files $check = "ok" Else $errmsg = "Update cannot continue - the F: drive is not present." Goto END EndIf ?"Checking for necessary disk space ..." Sleep 2 If $HDspace < 179200 $errmsg = "Disk space is insufficient for Win2K PRO Service Pack 3 install" ?"Disk space is insufficient - terminating update." Sleep 4 Goto END Else ?"Disk space is sufficient." Sleep 2 Del("c:\efo\"+@WKSTA+".efo") CLS ?" Updates required. Please read message and click on OK." $Inst = MessageBox("Your PC needs to be updated to Windows 2000 Professional Service Pack 3." + " This install will begin when you click the OK button. Depending on your" + " network connection and the speed of your computer, this update can take" + " anywhere from 15 to 45 minutes. Please do not run any programs during this time." + " Your PC will reboot automatically when the update is complete." + Chr(13) + Chr(10) + "" + Chr(13) + Chr(10) + "We apologize for any inconvenience that this may cause you, but this update" + " is necessary to keep your PC in compliance with security standards." + Chr(13) + Chr(10) + "","WFSC System Updates",48) CLS ??"" ?" Initiating install..." ??" Please be patient. DO NOT CANCEL THIS PROCESS!" ?" DOING SO COULD CAUSE YOUR PC TO MALFUNCTION." ??" Your PC will reboot when the update is complete." Shell "%comspec% /c f:\EFOupdts\w2k\W2ksp3\i386\update\update.exe -u -f -n -o -z" If @ERROR = "1603" $RC = MessageBox(@FULLNAME+", please do not cancel the update process. This update" + " is required for your PC to meet security standards. " + Chr(13) + Chr(10) + "" + Chr(13) + Chr(10) + "Please click RETRY to restart the update program. If you choose" + " to click cancel, your user information will be logged. " + Chr(13) + Chr(10) + "You will prompted to perform the update each" + " time you log on." + Chr(13) + Chr(10) + "" + Chr(13) + Chr(10) + "Thank you.","Cancellation Warning",21) If $RC = 4 Shell "%comspec% /c f:\EFOupdts\w2k\W2ksp3\i386\update\update.exe -u -f -n -o -z" If @ERROR = "1603" Shell '%comspec% /c echo @TIME @DATE @USERID @WKSTA - Win2K Service Pack 3' + ' installation began at '+$start+' and was cancelled by the user.' + '>> \\servername\efolan\efoupdts\errors\aborted.err' Goto End EndIf Else Shell '%comspec% /c echo @TIME @DATE @USERID @WKSTA - Win2K Service Pack 3' + ' installation began at '+$start+' and was cancelled by the user.' + '>> \\servername\efolan\efoupdts\errors\aborted.err' Goto END EndIf EndIf CLS ??" Updating the registry ..." $RC = WriteValue("HKEY_LOCAL_MACHINE\Software\EFO\Installed By Script\ServicePacks\SP1","InstallDate","@DATE","Reg_SZ") $RC = WriteValue("HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU","NoAutoUpdate","1","Reg_DWORD") ?" Update complete." $stop = @TIME ??"Updating installation log..." Shell '%comspec% /c echo @TIME @DATE @USERID @WKSTA - Win2K Service Pack 3' + ' installation began at '+$start+' and ended at '+$stop + '>> \\servername\efolan\efoupdts\errors\timelog.err' ??" Initiating system shutdown" Sleep 3 $RC = Shutdown("", "System will now reboot to enable new settings.", 10, 1, 1) EndIf EndIf Goto END ;this is here because there is actually a lot more code before the END label :END If $errmsg <> "" Shell '%comspec% /c echo @TIME @DATE @USERID @FULLNAME @WKSTA - '+$errmsg+'>> \\servername\efolan\efoupdts\errors\errors.err' EndIf Exit
[ 03. March 2003, 16:42: Message edited by: Jtel ]
|
|
Top
|
|
|
|
#37201 - 2003-03-03 01:57 PM
Re: Problems with error messages
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Jtel,
This post is hard to read.. Can you please break up the long lines?
Kent
|
|
Top
|
|
|
|
#37202 - 2003-03-03 02:18 PM
Re: Problems with error messages
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
Hmmm ... I copied the scriptlet and took the freedom to do that :
If $spack < 3 $start = @TIME If Exist("f:\EFOupdts\w2k\W2ksp3\i386\update\update.exe") ;check for 'F' drive mapped to local server for source files $check = "ok" Else $errmsg = "Update cannot continue - the F: drive is not present." Goto END EndIf ?"Checking for necessary disk space ..." Sleep 2 If $HDspace < 179200 $errmsg = "Disk space is insufficient for Win2K PRO Service Pack 3 install" ?"Disk space is insufficient - terminating update." Sleep 4 Goto END Else ?"Disk space is sufficient." Sleep 2 Del("c:\efo\"+@WKSTA+".efo") CLS ?" Updates required. Please read message and click on OK." $Inst = MessageBox("Your PC needs to be updated to Windows 2000 Professional Service Pack 3." + " This install will begin when you click the OK button. Depending on your" + " network connection and the speed of your computer, this update can take" + " anywhere from 15 to 45 minutes. Please do not run any programs during this time." + " Your PC will reboot automatically when the update is complete." + Chr(13) + Chr(10) + "" + Chr(13) + Chr(10) + "We apologize for any inconvenience that this may cause you, but this update" + " is necessary to keep your PC in compliance with security standards." + Chr(13) + Chr(10) + "","WFSC System Updates",48) CLS ??"" ?" Initiating install..." ??" Please be patient. DO NOT CANCEL THIS PROCESS!" ?" DOING SO COULD CAUSE YOUR PC TO MALFUNCTION." ??" Your PC will reboot when the update is complete." Shell "%comspec% /c f:\EFOupdts\w2k\W2ksp3\i386\update\update.exe -u -f -n -o -z" If @ERROR = "1603" $RC = MessageBox(@FULLNAME+", please do not cancel the update process. This update" + " is required for your PC to meet security standards. " + Chr(13) + Chr(10) + "" + Chr(13) + Chr(10) + "Please click RETRY to restart the update program. If you choose" + " to click cancel, your user information will be logged. " + Chr(13) + Chr(10) + "You will prompted to perform the update each" + " time you log on." + Chr(13) + Chr(10) + "" + Chr(13) + Chr(10) + "Thank you.","Cancellation Warning",21) If $RC = 4 Shell "%comspec% /c f:\EFOupdts\w2k\W2ksp3\i386\update\update.exe -u -f -n -o -z" If @ERROR = "1603" Shell '%comspec% /c echo @TIME @DATE @USERID @WKSTA - Win2K Service Pack 3' + ' installation began at '+$start+' and was cancelled by the user.' + '>> \\servername\efolan\efoupdts\errors\aborted.err' Goto End EndIf Else Shell '%comspec% /c echo @TIME @DATE @USERID @WKSTA - Win2K Service Pack 3' + ' installation began at '+$start+' and was cancelled by the user.' + '>> \\servername\efolan\efoupdts\errors\aborted.err' Goto END EndIf EndIf CLS ??" Updating the registry ..." $RC = WriteValue("HKEY_LOCAL_MACHINE\Software\EFO\Installed By Script\ServicePacks\SP1","InstallDate","@DATE","Reg_SZ") $RC = WriteValue("HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU","NoAutoUpdate","1","Reg_DWORD") ?" Update complete." $stop = @TIME ??"Updating installation log..." Shell '%comspec% /c echo @TIME @DATE @USERID @WKSTA - Win2K Service Pack 3' + ' installation began at '+$start+' and ended at '+$stop + '>> \\servername\efolan\efoupdts\errors\timelog.err' ??" Initiating system shutdown" Sleep 3 $RC = Shutdown("", "System will now reboot to enable new settings.", 10, 1, 1) EndIf EndIf Goto END ;this isn't necessary !
:END If $errmsg <> "" Shell '%comspec% /c echo @TIME @DATE @USERID @FULLNAME @WKSTA - '+$errmsg+'>> \\servername\efolan\efoupdts\errors\errors.err' EndIf Exit
Still I didn't found any cause of the errormessage redirected 3 times to the file
![[Frown]](images/icons/frown.gif) [ 03. March 2003, 14:24: Message edited by: jpols ]
_________________________
|
|
Top
|
|
|
|
#37205 - 2003-03-03 04:36 PM
Re: Problems with error messages
|
Jtel
Fresh Scripter
Registered: 2002-04-13
Posts: 41
|
Jens, thanks for the constructive criticism. As for the badly coded script – give me a break , this is only one small section of it – I didn’t see the need to post the entire script. There are checks for OS type, current service pack level, installed hotfixes, and admin privileges.
Why use a UNC instead of a mapped drive? In this case, the drive was mapped to the closest and fastest server out of a pool of 10 across the country (part of the script not included in the original post). There will always be a drive mapped to one of these servers – if for some reason one server was not available, it would map to the next closest one. This way the drive letter and source files remain the same and there are no issues with remembered UNCs that might not exist for any given reason.
I’ll take your advice on the WRITELINE for writing to the error log.
If you don’t mind, explain why GOTO shouldn’t be used and what is the best way to accomplish the task.
Thanks
|
|
Top
|
|
|
|
#37207 - 2003-03-03 04:59 PM
Re: Problems with error messages
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
this is what I use...
code:
if @ras=0 and $admin=1 and $Location<>"00" ;Do not run section if dialed up or not local admin ; ****************************** Win2k Service Pack 3 ***************************************** if $os="Win2k" and @csd<>"Service Pack 3" if updateapp("Win2kSP3",3)="yes" $=sendmessage(@wksta," The computer will automatically restart when complete.@CRLF This will take about 10-15 minutes.") $=writevalue("$HKLMS\Microsoft\Ole","LegacyImpersonationLevel","2",REG_DWORD) md %windir%\sp3 $=Writeprofilestring("$logon\inventory\Install.log","Win2kSP3","@wksta","@date") shell'$setup\servicepacks\win2ksp3\w2ksp3.exe /U /X:%windir%\sp3' run '%windir%\sp3\i386\update\update.exe /q /N /F ' $m=split("A CRITICAL Update is NOW taking place. Please do not open any programs until your system reboots and starts again._ This Update will take about 10-15 minutes.,The Upgrade is running. Please do not open any programs._ The Upgrade will be complete in about 15 minutes and your computer will restart.,A CRITICAL Update is NOW taking place. Please do not open any programs_ until your system reboots and starts again. This Update will take about 10-15 minutes.",chr(44)) while 1 for $l = 0 to 2 $press=Messagebox($m[$l], "Message from MIS",0) next loop quit endif endif endif
[ 03. March 2003, 20:58: Message edited by: Radimus ]
|
|
Top
|
|
|
|
#37208 - 2003-03-03 08:34 PM
Re: Problems with error messages
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
|
|
Top
|
|
|
|
#37209 - 2003-03-03 08:57 PM
Re: Problems with error messages
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 640 anonymous users online.
|
|
|