NDog Posted August 31, 2010 Posted August 31, 2010 This is my autoit script I use to deploy Java. It searches for old versions and removes them first. However using the RunWait(msiexec line 52 times is not as efficient as I would like it. I would like a simple way to create an array and then if it finds the msiexec line in the registry to call the msiexec remove feature. I am not too savvy with arrays yet, and would like a simple way to simply add new msi codes on a line, without having to declare each one indivually, if you know what I mean. I think this method would be faster overall at executing on a machine, searching registry for entries and only invoking msiexec if found, rather than invoking msiexec 52 times. Do you agree? Thanks for comments, suggestions expandcollapse popupOpt("TrayIconDebug", 1) $g_szVersion = "SmartNet" If WinExists($g_szVersion) Then Exit ; It's already running AutoItWinSetTitle($g_szVersion) HotKeySet("{ESC}", "MyExit") Func MyExit() Exit EndFunc #requireadmin $type = "System" $exe = "jre-6u21-windows-i586.exe" $dirrem = "jre1.6.0_21" $titlepre = "nul" $title = "nul" $processname = $exe $uninstallkey = "{26A24AE4-039D-4CA4-87B4-2F83216021FF}" $displayname = "Java(TM) 6 Update 21" $displayversion = "6.0.210" ;OLD VERSION UNINSTALLER RunWait("msiexec /qn /x {7148F0A8-6813-11D6-A77B-00B0D0142000}") RunWait("msiexec /qn /x {7148F0A8-6813-11D6-A77B-00B0D0142010}") RunWait("msiexec /qn /x {7148F0A8-6813-11D6-A77B-00B0D0142020}") RunWait("msiexec /qn /x {7148F0A8-6813-11D6-A77B-00B0D0142030}") RunWait("msiexec /qn /x {7148F0A8-6813-11D6-A77B-00B0D0142040}") RunWait("msiexec /qn /x {7148F0A8-6813-11D6-A77B-00B0D0142050}") RunWait("msiexec /qn /x {7148F0A8-6813-11D6-A77B-00B0D0142060}") RunWait("msiexec /qn /x {7148F0A8-6813-11D6-A77B-00B0D0142070}") RunWait("msiexec /qn /x {7148F0A8-6813-11D6-A77B-00B0D0142080}") RunWait("msiexec /qn /x {7148F0A8-6813-11D6-A77B-00B0D0142090}") RunWait("msiexec /qn /x {7148F0A8-6813-11D6-A77B-00B0D0142100}") RunWait("msiexec /qn /x {7148F0A8-6813-11D6-A77B-00B0D0142110}") RunWait("msiexec /qn /x {7148F0A8-6813-11D6-A77B-00B0D0142120}") RunWait("msiexec /qn /x {7148F0A8-6813-11D6-A77B-00B0D0142130}") RunWait("msiexec /qn /x {7148F0A8-6813-11D6-A77B-00B0D0142140}") RunWait("msiexec /qn /x {7148F0A8-6813-11D6-A77B-00B0D0142150}") RunWait("msiexec /qn /x {7148F0A8-6813-11D6-A77B-00B0D0142160}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0150000}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0150010}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0150020}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0150030}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0150040}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0150050}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0150060}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0150070}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0150080}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0150090}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0150100}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0150110}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0150120}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0150130}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0150140}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0160000}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0160010}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0160020}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0160030}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0160040}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0160050}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0160060}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0160070}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0160080}") RunWait("msiexec /qn /x {3248F0A8-6813-11D6-A77B-00B0D0160090}") RunWait("msiexec /qn /x {26A24AE4-039D-4CA4-87B4-2F83216010FF}") RunWait("msiexec /qn /x {26A24AE4-039D-4CA4-87B4-2F83216011FF}") RunWait("msiexec /qn /x {26A24AE4-039D-4CA4-87B4-2F83216012FF}") RunWait("msiexec /qn /x {26A24AE4-039D-4CA4-87B4-2F83216013FF}") RunWait("msiexec /qn /x {26A24AE4-039D-4CA4-87B4-2F83216014FF}") RunWait("msiexec /qn /x {26A24AE4-039D-4CA4-87B4-2F83216015FF}") RunWait("msiexec /qn /x {26A24AE4-039D-4CA4-87B4-2F83216016FF}") RunWait("msiexec /qn /x {26A24AE4-039D-4CA4-87B4-2F83216017FF}") RunWait("msiexec /qn /x {26A24AE4-039D-4CA4-87B4-2F83216018FF}") RunWait("msiexec /qn /x {26A24AE4-039D-4CA4-87B4-2F83216019FF}") RunWait("msiexec /qn /x {26A24AE4-039D-4CA4-87B4-2F83216020FF}") $uninstallname = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $uninstallkey, "DisplayName") $uninstallversion = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $uninstallkey, "DisplayVersion") If $uninstallname <> $displayname then If $uninstallversion <> $displayversion then Install() EndIf EndIf Exit Func Install() If Not ProcessExists($processname) Then Run(@ScriptDir & "\..\" & $type & "\" & $exe & " /passive") EndIf While ProcessExists($processname) Sleep(500) WEnd RunWait(@ProgramFilesDir & "\Java\jre6\bin\jqs.exe" & " -unregister") RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","SunJavaUpdateSched") RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Update\Policy","PromptAutoUpdateCheck") RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Update\Policy","Frequency") RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Update\Policy","UpdateSchedule") RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Update\Policy", "EnableJavaUpdate", "REG_DWORD", "0") RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Update\Policy", "NotifyDownload", "REG_DWORD", "0") RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Update\Policy", "NotifyInstall", "REG_DWORD", "0") DirRemove(@AppDataDir & "\Sun\Java\" & $dirrem,1) DirRemove(@AppDataDir & "\LocalLow\Sun\Java\" & $dirrem,1) EndFunc
Varian Posted August 31, 2010 Posted August 31, 2010 Here is the Array part. Now exactly where would you try to search for the registry key? I took a stab at it but modify to suit your needs. $Array = StringSplit("{{7148F0A8-6813-11D6-A77B-00B0D0142000},{7148F0A8-6813-11D6-A77B-00B0D0142010}," & _ "{7148F0A8-6813-11D6-A77B-00B0D0142020},{7148F0A8-6813-11D6-A77B-00B0D0142030},{7148F0A8-6813-11D6-A77B-00B0D0142040}," & _ "{7148F0A8-6813-11D6-A77B-00B0D0142050},{7148F0A8-6813-11D6-A77B-00B0D0142060},{7148F0A8-6813-11D6-A77B-00B0D0142070}," & _ "{7148F0A8-6813-11D6-A77B-00B0D0142080},{7148F0A8-6813-11D6-A77B-00B0D0142090},{7148F0A8-6813-11D6-A77B-00B0D0142100}," & _ "{7148F0A8-6813-11D6-A77B-00B0D0142110},{7148F0A8-6813-11D6-A77B-00B0D0142120},{7148F0A8-6813-11D6-A77B-00B0D0142130}," & _ "{7148F0A8-6813-11D6-A77B-00B0D0142140},{7148F0A8-6813-11D6-A77B-00B0D0142150},{7148F0A8-6813-11D6-A77B-00B0D0142160}," & _ "{3248F0A8-6813-11D6-A77B-00B0D0150000},{3248F0A8-6813-11D6-A77B-00B0D0150010},{3248F0A8-6813-11D6-A77B-00B0D0150020}," & _ "{3248F0A8-6813-11D6-A77B-00B0D0150030},{3248F0A8-6813-11D6-A77B-00B0D0150040},{3248F0A8-6813-11D6-A77B-00B0D0150050}," & _ "{3248F0A8-6813-11D6-A77B-00B0D0150060},{3248F0A8-6813-11D6-A77B-00B0D0150070},{3248F0A8-6813-11D6-A77B-00B0D0150080}," & _ "{3248F0A8-6813-11D6-A77B-00B0D0150090},{3248F0A8-6813-11D6-A77B-00B0D0150100},{3248F0A8-6813-11D6-A77B-00B0D0150110}," & _ "{3248F0A8-6813-11D6-A77B-00B0D0150120},{3248F0A8-6813-11D6-A77B-00B0D0150130},{3248F0A8-6813-11D6-A77B-00B0D0150140}," & _ "{3248F0A8-6813-11D6-A77B-00B0D0160000},{3248F0A8-6813-11D6-A77B-00B0D0160010},{3248F0A8-6813-11D6-A77B-00B0D0160020}," & _ "{3248F0A8-6813-11D6-A77B-00B0D0160030},{3248F0A8-6813-11D6-A77B-00B0D0160040},{3248F0A8-6813-11D6-A77B-00B0D0160050}," & _ "{3248F0A8-6813-11D6-A77B-00B0D0160060},{3248F0A8-6813-11D6-A77B-00B0D0160070},{3248F0A8-6813-11D6-A77B-00B0D0160080}," & _ "{3248F0A8-6813-11D6-A77B-00B0D0160090},{26A24AE4-039D-4CA4-87B4-2F83216010FF},{26A24AE4-039D-4CA4-87B4-2F83216011FF}," & _ "{26A24AE4-039D-4CA4-87B4-2F83216012FF},{26A24AE4-039D-4CA4-87B4-2F83216013FF},{26A24AE4-039D-4CA4-87B4-2F83216014FF}," & _ "{26A24AE4-039D-4CA4-87B4-2F83216015FF},{26A24AE4-039D-4CA4-87B4-2F83216016FF},{26A24AE4-039D-4CA4-87B4-2F83216017FF}," & _ "{26A24AE4-039D-4CA4-87B4-2F83216018FF},{26A24AE4-039D-4CA4-87B4-2F83216019FF},{26A24AE4-039D-4CA4-87B4-2F83216020FF}", ",") For $i = 1 to $Array[0] Local $InstallCeck = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $Array[$i], "") If Not @error Then RunWait("msiexec /qn /x " & $Array[$i]) Next
NDog Posted September 10, 2010 Author Posted September 10, 2010 Thanks for the reply, tested it for a few weeks now and is working good. I have attached the full code for anyone who wants it. Thanks again for your kind reply Varian Regards expandcollapse popupOpt("TrayIconDebug", 1) $g_szVersion = "SmartNet" If WinExists($g_szVersion) Then Exit ; It's already running AutoItWinSetTitle($g_szVersion) HotKeySet("{ESC}", "MyExit") Func MyExit() Exit EndFunc #requireadmin $type = "System" $exe = "jre-6u21-windows-i586.exe" $dirrem = "jre1.6.0_21" $titlepre = "nul" $title = "nul" $processname = $exe $uninstallkey = "{26A24AE4-039D-4CA4-87B4-2F83216021FF}" $displayname = "Java(TM) 6 Update 21" $displayversion = "6.0.210" ;OLD VERSION UNINSTALLER $Array = StringSplit("{7148F0A8-6813-11D6-A77B-00B0D0142000},{7148F0A8-6813-11D6-A77B-00B0D0142010}," & _ "{7148F0A8-6813-11D6-A77B-00B0D0142020},{7148F0A8-6813-11D6-A77B-00B0D0142030},{7148F0A8-6813-11D6-A77B-00B0D0142040}," & _ "{7148F0A8-6813-11D6-A77B-00B0D0142050},{7148F0A8-6813-11D6-A77B-00B0D0142060},{7148F0A8-6813-11D6-A77B-00B0D0142070}," & _ "{7148F0A8-6813-11D6-A77B-00B0D0142080},{7148F0A8-6813-11D6-A77B-00B0D0142090},{7148F0A8-6813-11D6-A77B-00B0D0142100}," & _ "{7148F0A8-6813-11D6-A77B-00B0D0142110},{7148F0A8-6813-11D6-A77B-00B0D0142120},{7148F0A8-6813-11D6-A77B-00B0D0142130}," & _ "{7148F0A8-6813-11D6-A77B-00B0D0142140},{7148F0A8-6813-11D6-A77B-00B0D0142150},{7148F0A8-6813-11D6-A77B-00B0D0142160}," & _ "{3248F0A8-6813-11D6-A77B-00B0D0150000},{3248F0A8-6813-11D6-A77B-00B0D0150010},{3248F0A8-6813-11D6-A77B-00B0D0150020}," & _ "{3248F0A8-6813-11D6-A77B-00B0D0150030},{3248F0A8-6813-11D6-A77B-00B0D0150040},{3248F0A8-6813-11D6-A77B-00B0D0150050}," & _ "{3248F0A8-6813-11D6-A77B-00B0D0150060},{3248F0A8-6813-11D6-A77B-00B0D0150070},{3248F0A8-6813-11D6-A77B-00B0D0150080}," & _ "{3248F0A8-6813-11D6-A77B-00B0D0150090},{3248F0A8-6813-11D6-A77B-00B0D0150100},{3248F0A8-6813-11D6-A77B-00B0D0150110}," & _ "{3248F0A8-6813-11D6-A77B-00B0D0150120},{3248F0A8-6813-11D6-A77B-00B0D0150130},{3248F0A8-6813-11D6-A77B-00B0D0150140}," & _ "{3248F0A8-6813-11D6-A77B-00B0D0160000},{3248F0A8-6813-11D6-A77B-00B0D0160010},{3248F0A8-6813-11D6-A77B-00B0D0160020}," & _ "{3248F0A8-6813-11D6-A77B-00B0D0160030},{3248F0A8-6813-11D6-A77B-00B0D0160040},{3248F0A8-6813-11D6-A77B-00B0D0160050}," & _ "{3248F0A8-6813-11D6-A77B-00B0D0160060},{3248F0A8-6813-11D6-A77B-00B0D0160070},{3248F0A8-6813-11D6-A77B-00B0D0160080}," & _ "{3248F0A8-6813-11D6-A77B-00B0D0160090},{26A24AE4-039D-4CA4-87B4-2F83216010FF},{26A24AE4-039D-4CA4-87B4-2F83216011FF}," & _ "{26A24AE4-039D-4CA4-87B4-2F83216012FF},{26A24AE4-039D-4CA4-87B4-2F83216013FF},{26A24AE4-039D-4CA4-87B4-2F83216014FF}," & _ "{26A24AE4-039D-4CA4-87B4-2F83216015FF},{26A24AE4-039D-4CA4-87B4-2F83216016FF},{26A24AE4-039D-4CA4-87B4-2F83216017FF}," & _ "{26A24AE4-039D-4CA4-87B4-2F83216018FF},{26A24AE4-039D-4CA4-87B4-2F83216019FF},{26A24AE4-039D-4CA4-87B4-2F83216020FF}", ",") For $i = 1 to $Array[0] Local $InstallCheck = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $Array[$i], "") If @error == -1 Then RunWait("msiexec /qn /x " & $Array[$i]) Next $Array = StringSplit("{26A24AE4-039D-4CA4-87B4-2F83216010F0},{26A24AE4-039D-4CA4-87B4-2F83216011F0}," & _ "{26A24AE4-039D-4CA4-87B4-2F83216012F0},{26A24AE4-039D-4CA4-87B4-2F83216013F0},{26A24AE4-039D-4CA4-87B4-2F83216014F0}," & _ "{26A24AE4-039D-4CA4-87B4-2F83216015F0},{26A24AE4-039D-4CA4-87B4-2F83216016F0},{26A24AE4-039D-4CA4-87B4-2F83216017F0}," & _ "{26A24AE4-039D-4CA4-87B4-2F83216018F0},{26A24AE4-039D-4CA4-87B4-2F83216019F0},{26A24AE4-039D-4CA4-87B4-2F83216020F0}", ",") For $i = 1 to $Array[0] Local $InstallCheck = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $Array[$i], "") If @error == -1 Then RunWait("msiexec /qn /x " & $Array[$i]) Next $uninstallname = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $uninstallkey, "DisplayName") $uninstallversion = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $uninstallkey, "DisplayVersion") If $uninstallname <> $displayname then If $uninstallversion <> $displayversion then Install() EndIf EndIf Exit Func Install() If Not ProcessExists($processname) Then Run(@ScriptDir & "\..\" & $type & "\" & $exe & " /passive") EndIf While ProcessExists($processname) Sleep(500) WEnd RunWait(@ProgramFilesDir & "\Java\jre6\bin\jqs.exe" & " -unregister") RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","SunJavaUpdateSched") RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Update\Policy","PromptAutoUpdateCheck") RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Update\Policy","Frequency") RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Update\Policy","UpdateSchedule") RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Update\Policy", "EnableJavaUpdate", "REG_DWORD", "0") RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Update\Policy", "NotifyDownload", "REG_DWORD", "0") RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Update\Policy", "NotifyInstall", "REG_DWORD", "0") DirRemove(@AppDataDir & "\Sun\Java\" & $dirrem,1) DirRemove(@AppDataDir & "\LocalLow\Sun\Java\" & $dirrem,1) EndFunc
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now