;~ #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 #Tidy_Parameters=/sort_funcs /reel #AutoIt3Wrapper_Run_Tidy=Y #Region _JavaManagement.au3 - UDF Includes #include-once #include "IE.au3" #include #include #EndRegion _JavaManagement.au3 - UDF Includes #Region JavaManagement.au3 - UDF Header ; #INDEX# ======================================================================== ; Title .........: JavaManagement.au3 ; AutoIt Version : 3.3.10.2++ ; Language ......: English ; Description ...: This UDF is not designed to interact with JAVA, but to manage JAVA Settings and Environment ; Author ........: mLipok ; Modified ......: ; Version .......: 2016/03/04 ; ================================================================================ #CS 2016/03/04 . First public version . NoDoc - only example . . . @LAST . . #CE #EndRegion JavaManagement.au3 - UDF Header #Region _JavaManagement.au3 - Variables Global Enum _ $JAVAMAN_DIRJAVADEPLOYMENT, _ $JAVAMAN_FILEEXCEPTIONSITES, _ $JAVAMAN_ISLATESTVERSION, _ $JAVAMAN_COUNTER #EndRegion _JavaManagement.au3 - Variables ; Preset _JavaMan_ResetSettings() #Region _JavaManagement.au3 - EXAMPLES If Not @Compiled And @ScriptName = 'JavaManagement.au3' Then Local $aRecommendedVersion = _JavaMan_Version_Latest() If Not @error Then _ArrayDisplay($aRecommendedVersion, '$aRecommendedVersion') EndIf Local $aInstaledVersion = _JavaMan_Version_Instaled() If Not @error Then _ArrayDisplay($aInstaledVersion, '$aInstaledVersion') EndIf MsgBox($MB_ICONINFORMATION, '_JavaMan_Version_IsLatest()', _JavaMan_Version_IsLatest()) EndIf #EndRegion _JavaManagement.au3 - EXAMPLES #Region _JavaManagement.au3 - Functions Func _JavaMan_ExceptionAdd($sURL) If Not FileExists(__JavaMan_API($JAVAMAN_FILEEXCEPTIONSITES)) Then FileWrite(__JavaMan_API($JAVAMAN_FILEEXCEPTIONSITES), '') Local $sJavaExceptionListOrgContent = FileRead(__JavaMan_API($JAVAMAN_FILEEXCEPTIONSITES)) If Not StringInStr($sJavaExceptionListOrgContent, $sURL) Then FileWriteLine(__JavaMan_API($JAVAMAN_FILEEXCEPTIONSITES), $sURL) EndFunc ;==>_JavaMan_ExceptionAdd Func _JavaMan_JavaPolicy_GetConent() Local $sURL = 'http://www.java.com/en/download/manual.jsp' If Not FileExists(__JavaMan_API($JAVAMAN_FILEEXCEPTIONSITES)) Then FileWrite(__JavaMan_API($JAVAMAN_FILEEXCEPTIONSITES), '') Local $sJavaExceptionListOrgContent = FileRead(__JavaMan_API($JAVAMAN_FILEEXCEPTIONSITES)) If Not StringInStr($sJavaExceptionListOrgContent, $sURL) Then FileWriteLine(__JavaMan_API($JAVAMAN_FILEEXCEPTIONSITES), $sURL) EndFunc ;==>_JavaMan_JavaPolicy_GetConent Func _JavaMan_ProgramFiles_JavaDir() _JavaMan_Version_Instaled() If @error Then Return SetError(@error, @extended, 0) ; TODO Refactoring Local Static $sJavaDir = @ProgramFilesDir & '\Java\' & _JavaMan_Version_Instaled()[4] Return $sJavaDir EndFunc ;==>_JavaMan_ProgramFiles_JavaDir Func _JavaMan_ResetSettings() __JavaMan_API(Null) EndFunc ;==>_JavaMan_ResetSettings Func _JavaMan_Version_Instaled() Local $aJavaVersion_temp[5] = ['', '', '', '', ''] Local $aResult = __JavaMan_RunWrapper('java -version 2') If @error Then Return SetError(1, @error, $aJavaVersion_temp) #CS C:\Users\User>java -version 2 java version "1.8.0_25" Java(TM) SE Runtime Environment (build 1.8.0_25-b18) Java HotSpot(TM) Client VM (build 25.25-b02, mixed mode, sharing) #CE Local $aJavaVersion = StringRegExp($aResult[1], '(?i)java version "(\d+)\.(\d+)\.(\d+)_(\d+)"', $STR_REGEXPARRAYGLOBALMATCH) If @error Then Return SetError(2, @error, $aJavaVersion_temp) Local $aTemp = StringRegExp($aResult[1], '(?i)java version "(\d+\.\d+\.\d+_\d+)"', $STR_REGEXPARRAYGLOBALMATCH) If @error Then Return SetError(2, @error, $aJavaVersion_temp) _ArrayAdd($aJavaVersion, $aTemp[0]) Return SetError(0, 0, $aJavaVersion) EndFunc ;==>_JavaMan_Version_Instaled Func _JavaMan_Version_IsLatest() Local $aRecommendedVersion = _JavaMan_Version_Latest() Local $aInstaledVersion = _JavaMan_Version_Instaled() Return (1 = StringRegExp($aInstaledVersion[4], '\.' & $aRecommendedVersion[0] & '\.' & '.+_' & $aRecommendedVersion[1], $STR_REGEXPMATCH)) EndFunc ;==>_JavaMan_Version_IsLatest Func _JavaMan_Version_Latest() Local $sURL = 'http://www.java.com/en/download/manual.jsp' Local $oIE = _IECreate($sURL, 0, 0) If @error Then Return SetError(1, @error, '') #CS Recommended Version 8 Update 60 Release date August 18, 2015 #CE Local $sTXT_Content = _IEBodyReadText($oIE) Local $aJavaVersion = StringRegExp($sTXT_Content, '(?i)Recommended Version (\d+) Update (\d+)', $STR_REGEXPARRAYGLOBALMATCH) If @error Then Return SetError(2, @error, '') Return SetError(0, 0, $aJavaVersion) EndFunc ;==>_JavaMan_Version_Latest #EndRegion _JavaManagement.au3 - Functions #Region _JavaManagement.au3 - Internal Functions Func __JavaMan_API($vParam = Default) Local Static $bFirstRun = True Local Static $aJava_API[$JAVAMAN_COUNTER] If $bFirstRun = True Or $vParam = Null Then $aJava_API[$JAVAMAN_DIRJAVADEPLOYMENT] = @UserProfileDir & '\AppData\LocalLow\Sun\Java\Deployment\' $aJava_API[$JAVAMAN_FILEEXCEPTIONSITES] = $aJava_API[$JAVAMAN_DIRJAVADEPLOYMENT] & 'security\exception.sites' ; TODO ; $aJava_API[$JAVAMAN_ISLATESTVERSION] = $bFirstRun = False EndIf If $vParam = Default Then Return SetError(0, 0, $aJava_API) ElseIf Not IsInt($vParam) Then Return SetError(1, 0, 0) ElseIf $vParam > $JAVAMAN_COUNTER - 1 Then Return SetError(2, 0, 0) EndIf Return SetError(0, 0, $aJava_API[$vParam]) EndFunc ;==>__JavaMan_API Func __JavaMan_RunWrapper($sProgram, $sWorksDir = @SystemDir, $iShow_Flag = @SW_HIDE, $iOpt_Flag = $STDERR_CHILD + $STDOUT_CHILD) Local $iPID = Run(@ComSpec & " /c " & $sProgram, $sWorksDir, $iShow_Flag, $iOpt_Flag) If @error Then Return SetError(1, @error, '') Local $sOutput = "" While 1 $sOutput &= StdoutRead($iPID) If @error Then ; Exit the loop if the process closes or StdoutRead returns an error. ExitLoop EndIf WEnd Local $sError = "" While 1 $sError &= StderrRead($iPID) If @error Then ; Exit the loop if the process closes or StderrRead returns an error. ExitLoop EndIf WEnd Local $aResult[2] = [$sOutput, $sError] Return $aResult EndFunc ;==>__JavaMan_RunWrapper #EndRegion _JavaManagement.au3 - Internal Functions #Region _JavaManagement.au3 - TODO ;~ http://www.itninja.com/question/silent-uninstall-java-all-versions ;~ http://www.symantec.com/connect/forums/looking-script-uninstall-all-previous-versions-java-win7x64 ;~ http://blogs.technet.com/b/jchalfant/archive/2014/05/13/uninstalling-all-previous-versions-of-java-runtime-environment-using-application-supersedence-in-configuration-manager.aspx ;~ https://www.java.com/en/download/faq/release_dates.xml #EndRegion _JavaManagement.au3 - TODO