rohlando
(Fresh Scripter)
2003-08-25 09:33 PM
Need advice on uninstall script

Good Day...
I am kind of new to Kix as our company has just
purchased ScriptLogic product. With the new
purchase I have been selected to be the first to
use and setup the application. I am looking at a
custom script which was posted on the board
sometime ago, and tried to improve on it to use
for our company. I have used one of the UDFs for
loging information, to track my progress. If
someone could provide me any insight to issues
with my script, I would be very thankful.

code:
;===============================================================================================
;**** Last Modified on 8/25/2003 at 2:22:10 PM by JRohland ****
;===============================================================================================
;
;Uninstall Acrobat Reader 4.x, 5.x and install 6.x only if the Windows Journal Viewer is not installed.
;Our company has found if the Windows Journal is installed when installing Adobe Reader 6, the system
;does not let the install finish.
;
;Script requires SLexec, SLShortcut, SLRegWriteVal, SLRegAddKey from Script Logic
;
Break On
;Load Constants and variables
;---------------------------------------------------------------------------------------------------
$softloc1 = "\\servera\Software\Software\Adobe Reader\AdobeRead6\"
$softloc2 = "\\serverb\Software\Software\Adobe Reader\AdobeRead6\"
$softloc3 = "\\serverc\Software\Software\Adobe Reader\AdobeRead6\"

$iparray=Split(@IPADDRESS0,'.')
Select
Case LTrim($iparray[2]) = 1
$installfrom = $softloc1
Case LTrim($iparray[2]) = 2
$installfrom = $softloc2
Case LTrim($iparray[2]) = 3
$installfrom = $softloc3
Case 1
Goto End
EndSelect

$PCMICANT = ReadValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Pcmcia","Start")
$PCMCIA9X0 = ExistKey("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\PCMCIA\0000")
$PCMCIA9X1 = ExistKey("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\PCMCIA\0001")
$Selection = 0
$loopbreak = 0
$logfile = "c:\temp\test.txt"


$WJ = UninstallChk("DisplayName","Microsoft Windows Journal Viewer")
$AR6 = UninstallChk("DisplayName","Adobe Reader 6.0")
$AR45 = UninstallChk("DisplayName","Adobe Acrobat 4.0, 5.0")
$AR5 = UninstallChk("DisplayName","Adobe Acrobat 5.0")
$AR4 = UninstallChk("DisplayName","Adobe Acrobat 4.0")

WriteLog2($logfile,"WJ0 : "+$wj[0],1)
WriteLog2($logfile,"WJ1 : "+$wj[1],1)
WriteLog2($logfile,"WJ2 : "+$wj[2],1)
WriteLog2($logfile,"----------------------------------------------------------------")
WriteLog2($logfile,"AR60 : "+$AR6[0],1)
WriteLog2($logfile,"AR61 : "+$AR6[1],1)
WriteLog2($logfile,"AR62 : "+$AR6[2],1)
WriteLog2($logfile,"----------------------------------------------------------------")
WriteLog2($logfile,"AR50 : "+$AR5[0],1)
WriteLog2($logfile,"AR51 : "+$AR5[1],1)
WriteLog2($logfile,"AR52 : "+$AR5[2],1)
WriteLog2($logfile,"----------------------------------------------------------------")
WriteLog2($logfile,"AR450 : "+$AR45[0],1)
WriteLog2($logfile,"AR451 : "+$AR45[1],1)
WriteLog2($logfile,"AR452 : "+$AR45[2],1)
WriteLog2($logfile,"----------------------------------------------------------------")
WriteLog2($logfile,"AR40 : "+$AR4[0],1)
WriteLog2($logfile,"AR41 : "+$AR4[1],1)
WriteLog2($logfile,"AR42 : "+$AR4[2],1)

If $AR4[2]=1
$rc = SLexec($AR4[0],$AR4[1]+" -a",'Admin During')
$AR4U = UninstallChk("DisplayName","Adobe Acrobat 4.0")
If $AR4u[2]=1
MessageBox("Error trying to uninstall Adobe Acrobat 4.0. Please contact your system administrator.","Error Uninstalling Adobe",16)
WriteLog2($logfile,"Error uninstalling Adobe Acrobat 4.0 from @WKSTA",1)
GoTo End
Else
WriteLog2($logfile,"Uninstall of Adobe Acrobat 4.0 from @WKSTA SUCESSFUL!",1)
EndIf
EndIf

If $AR45[2]=1
$rc = SLexec($AR45[0],$AR45[1]+" -a",'Admin During')
$AR45U = UninstallChk("DisplayName","Adobe Acrobat 5.0")
If $AR45u[2]=1
MessageBox("Error trying to uninstall Adobe Acrobat 4.0 & 5.0. Please contact your system administrator.","Error Uninstalling Adobe",16)
WriteLog2($logfile,"Error uninstalling Adobe Acrobat 4.0 & 5.0 from @WKSTA for @USERID",1)
GoTo End
Else
WriteLog2($logfile,"Uninstall of Adobe Acrobat 4.0 & 5.0 from @WKSTA SUCESSFUL for @USERID!",1)
EndIf
EndIf

If $AR5[2]=1
$rc = SLexec($AR5[0],$AR5[1]+" -a",'Admin During')
$AR5U = UninstallChk("DisplayName","Adobe Acrobat 5.0")
If $AR5u[2]=1
MessageBox("Error trying to uninstall Adobe Acrobat 5.0. Please contact your system administrator.","Error Uninstalling Adobe",16)
WriteLog2($logfile,"Error uninstalling Adobe Acrobat 5.0 from @WKSTA for @USERID",1)
GoTo End
Else
WriteLog2($logfile,"Uninstall of Adobe Acrobat 5.0 from @WKSTA SUCESSFUL for @USERID!",1)
EndIf
EndIf

If $AR6[2]=1
WriteLog2($logfile,"Adobe Acrobat 6.0 currently Installed on @WKSTA for @USERID!",1)
GoTo End
EndIf

If $AR6[2]=0 AND $WJ[2]=1
MessageBox("@FULLNAME, we will need to make some software changes to your computer. Please press ok to continue, we will provide a message when completed.","@FullName software change Notice",64)
WriteLog2($logfile,"Unstall of Microsoft Windows Journal is required for @WKSTA before installing Adobe 6.0",1)
$rc = SLexec($WJ[0],Ltrim($WJ[1]),'Admin During')
$WJU = UninstallChk("DisplayName","Microsoft Windows Journal Viewer")
If $WJU[2]=1
MessageBox("Error trying to uninstall Microsoft Windows Journal Viewer. Please contact your system administrator.","Error Uninstalling Adobe",16)
WriteLog2($logfile,"Error uninstalling Microsoft Windows Journal Viewer from @WKSTA",1)
GoTo End
Else
WriteLog2($logfile,"Uninstall of Microsoft Windows Journal Viewer from @WKSTA SUCESSFUL for @USERID!",1)
If @INWIN=1
If $PCMICANT = 0
$Selection = MessageBox("Beacuse you are utilizing a laptop computer, you have the option to install Adobe 6 or to decline the install. If you decline the install, you will need to request the Information Systems Department to install the New version of the Reader. Please note if you did have an older version of the application, the system has uninstalled the application from your computer." + Chr(13) + Chr(10) + "" + Chr(13) + Chr(10) + "Would you like to install the New version?","Laptop Adobe 6 Reader Install",36)
Gosub acr6install
Else
$Selection = 6
Gosub acr6install
EndIf
Else
If $PCMCIA9X0 OR $PCMCIA9X1 = 0
MessageBox("Because your operating system is Windows 95, you can not install the newest version of the Adobe Reader. We no longer support the Windows 95 Operating Systems within the company.","Adobe 6 Install",48)
GoTo End
EndIf
EndIf
EndIf
EndIf

If $AR6[2]=0 AND $WJ[2]=0
$Selection = 6
Gosub acr6install
EndIf
;
;
:end
Exit

:acr6install
Select
Case $Selection = 6
WriteLog2($logfile,"Adobe Install of version 6 Selected",1)
?"Installing Acrobat 6, please wait....."
WriteLog2($logfile,"Adobe Install Started",1)
$AB61 = "msiexec.exe"
$AB62 = '/q ALLUSERS=2 /m MSILA3H3 /i "$installfrom\Adobe Reader 6.0.msi"'
WriteLog2($logfile,"Running Install command",1)
$rc = SLexec($AB61,$AB62,'Admin During')
$AR6u = UninstallChk("DisplayName","Adobe Reader 6.0")
WriteLog($logfile,"AR6u1 : "+$AR6u[0],1)
WriteLog($logfile,"AR6u2 : "+$AR6u[1],1)
WriteLog($logfile,"AR6u3 : "+$AR6u[2],1)
If $AR6u[2]=1
MessageBox("Error trying to install Adobe Acrobat 6.0. Please contact your system administrator.","Error Installing Adobe",16)
WriteLog2($logfile,"Error installing Adobe Acrobat 6.0 on @WKSTA",1)
GoTo End
Else
WriteLog2($logfile,"Install of Adobe Acrobat 6.0 on @WKSTA SUCESSFUL!",1)
EndIf
$allusers = 'C:\Documents and Settings\All Users\Start Menu\Programs\PrintMe Internet Printing'
$rc = SLShortcut('Delete',$allusers,'Download Driver')
If Exist 'C:\Documents and Settings\All Users\Start Menu\Programs\PrintMe Internet Printing\Download Driver.lnk'
WriteLog2($logfile,"Delete of Download Driver.lnk failed on @WKSTA",1)
EndIf
$rc = SLShortcut('Delete',$allusers,'Learn More')
If Exist 'C:\Documents and Settings\All Users\Start Menu\Programs\PrintMe Internet Printing\Learn More.lnk'
WriteLog2($logfile,"Delete of Learn More.lnk failed on @WKSTA",1)
EndIf
RD 'C:\Documents and Settings\All Users\Start Menu\Programs\PrintMe Internet Printing'
If Exist 'C:\Documents and Settings\All Users\Start Menu\Programs\PrintMe Internet Printing'
WriteLog2($logfile,"Removal of Directory failed on @WKSTA",1)
EndIf
$rc =SLRegAddKey('HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Acrobat Reader\6.0\AdobeViewer')
If $rc <> '0'
MessageBox('Acrobat 6 addkey failed.', 'Acrobat 6 installation', 64)
Else
$rc = SLRegWriteVal('HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Acrobat Reader\6.0\AdobeViewer', 'EULA', '1', 'REG_DWORD')
If $rc <> '0'
MessageBox('Acrobat 6 writevalue failed.', 'Acrobat 6 installation', 16)
EndIf
EndIf
Case $Selection = 7
$null = MessageBox("You will need to contact the Help Desk to install the new version of the software when you are avaible. Thank you.","Request for Install",64)
Case 1
GoTo End
EndSelect
Return



;FUNCTION WriteLog2()
;
;AUTHOR Howard A. Bullock (hbullock@tycoelectronics.com)
;
;ACTION Generic logging facility for scripts. Appends log entry to a file with an optional TimeStamp.
;
;SYNTAX WriteLog2($File, $text, [0|1])
;
;PARAMETERS $File (Required) - String value
; $text (Required) - String value
; $TimeStamp (Optional) Default(0) no TimeStamp (1 or 0)
;
;
;REMARKS This function writes (appends) an optionally time stamped log entry to the file defined in function.
; This function searches for the first unused file handle, open the file, and write the entry. T he file handle
; is then closed. When the function is unable to perform its it write the error is displayed&nbs p;in a message box.
;
;RETURNS Nothing
;
;DEPENDENCIES None
;
;EXAMPLES WriteLog2("junk.txt","This is a test")
; WriteLog2("junk.txt","This is a test",0)
; WriteLog2("junk.txt","This is a test",1)
;
;
Function WriteLog2($File, $Text, optional $TimeStamp)
;ACTION: Writes text to a specified log file.
Dim $RC, $File, $text, $FH, $TimeStamp
$FH=1
$RC=Open ($FH, $File, 5)
While $RC = -3
$FH=$FH +1
$RC=Open ($FH, $File, 5)
Loop
Select
Case $RC=0
If ($TimeStamp=1)
$TimeStamp = @Date + " " + @Time + " - "
Else
$TimeStamp = ""
EndIf
$RC=WriteLine ($FH, $TimeStamp + $Text + @CRLF)
$RC=Close ($FH)
Case $RC=-2
$text = "WriteLog2: Invalid file handle ($FH) specified when trying to Open $File."
$RC=MessageBox ($text,"Script Error",48)
Case $RC=-1
$text = "WriteLog2: Invalid file name ($File) specified for log file."
$RC=MessageBox ($text,"Script Error",48)
Case $RC=>0
$text = "System Error($RC) while attempting to open log file ($File)."
$RC=MessageBox ($text,"Script Error",48)
EndSelect
EndFunction


;FUNCTION UninstallChk()
;
;AUTHOR Rohlando
;
;ACTION Generic Uninstall Key Check to provide the Uninstall String for the uninstall process
;
;SYNTAX UninstallChk($text1, $text2)
;
;PARAMETERS $text1 (Required) - String value
; $text2 (Required) - String value
;
;
;REMARKS This function reads the HLM\Software\Windows\CurrentVersion\Uninstall sub key looking for $text1 in the Dataname.
; If the Dataname is found $text2 is compaired to value read from $text1. If matched, the uninstall string is read
; and parsed to the Uninstall Application and the Uninstall Application Parameters. If the search was unable to
; find a match the system returns 0 for Uninstall Application, Uninstall Applicatoin Parameters, and Match value of
; 0. If the search produces a match, the system Returns Uninstall Application, Uninstall Application Parameters, and
; the Match value of 1.
;
;RETURNS Uninstall Application
; Uninstall Application Parameters
; Match value (1=Sucess,0=Fail)
;
;DEPENDENCIES None
;
;EXAMPLES UninstallChk("DisplayName","Microsoft Windows Journal Viewer")
;
;

Function UninstallChk ($ReadValName,$CheckValName)

Dim $UninstallSubKey, $ReadValName, $CheckValName

$Match = 0
$UninstallSubKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
$KeyCount = 0
$CheckKey = EnumKey($UninstallSubKey, $KeyCount)

While @Error = 0
$CheckKey = EnumKey($UninstallSubKey, $KeyCount)
$fullkey = "$UninstallSubKey\$CheckKey"
$ReadVal = ReadValue($fullKey,$ReadValName)
If @Error = 0
If $ReadVal = $CheckValName
$Match = 1
$uninstallstring=ReadValue($fullkey,'UninstallString')
If $uninstallstring
$uninstallapp =SubStr($uninstallstring,1,InStr($uninstallstring," ")-1)
$uninstallargs=SubStr($uninstallstring,InStr($uninstallstring," "),Len($uninstallstring))
EndIf
EndIf
EndIf

$KeyCount = $KeyCount + 1
$CheckKey = EnumKey($UninstallSubKey, $KeyCount)
Loop

If $Match = 0
$uninstallapp = 0
$uninstallargs = 0
EndIf

$UninstallChk = $uninstallapp, $uninstallargs, $Match

EndFunction

If I run the script I recieve an error on the function I have created called $UninstallChk. The error produced is Script error: expected expression! $WJ=UninstallChk("DisplayName","Microsoft Windows Journal Viewer").

If I run the Function outside of ScriptLogic the
function returns the required results, as
expected. I am kind of lost trying to find the
error. If anyone could point it out I would be
thankful.

Thanks.

[ 25. August 2003, 21:47: Message edited by: rohlando ]


LonkeroAdministrator
(KiX Master Guru)
2003-08-25 09:51 PM
Re: Need advice on uninstall script

well,
you dim the vars that do not need dimming (the ones as arguments. those are automatically dimmed)

then, you don't dim at least vars:

KEYCOUNT
CHECKKEY
FULLKEY
READVAL
MATCH
UNISTALLAPP

as to start with.


 

 

 

 

[ 25. August 2003, 21:59: Message edited by: Lonkero ]


rohlando
(Fresh Scripter)
2003-08-25 10:43 PM
Re: Need advice on uninstall script

You are correct, thanks for helping a starter, this was my first attempt at a function.

Thanks, I do appricate your input.


LonkeroAdministrator
(KiX Master Guru)
2003-08-25 10:51 PM
Re: Need advice on uninstall script

no problem.
but I bet that didn't solve it yet.

or did it?


 


rohlando
(Fresh Scripter)
2003-08-25 11:10 PM
Re: Need advice on uninstall script

Nope.... Still the same issue, believe me I am trying to figure it out

MCA
(KiX Supporter)
2003-09-17 11:36 PM
Re: Need advice on uninstall script

Solved at the moment?
greetings.


rohlando
(Fresh Scripter)
2003-09-26 06:40 PM
Re: Need advice on uninstall script

Sorry for the late responce, no I still have not
solved the problem yet. Anyone with any advice, I would be thankful.....


Les
(KiX Master)
2003-09-26 07:00 PM
Re: Need advice on uninstall script

Please break the long lines in your post.

Sealeopard
(KiX Master)
2003-09-26 07:11 PM
Re: Need advice on uninstall script

Yes, break those !@#$ lines and use DEBUG ON in the first line of your code to step through it for debugging purposes.