ubelong2matt Posted November 25, 2014 Posted November 25, 2014 I apologize if this has been asked somewhere else. I consider myself a master of the Google-foo but, unfortunately, wording this search was turning up null to help me. Here's my issue. I have 12-checkboxes that I set to checked. I can, obviously, use If...Then statements to find out if the user kept them checked BUT I want to use a While loop to cycle through the checkboxes without having twelve different If...Then statements. All of the checkboxes are numbered 1-12 in the GUI (i.e. $checkbox1, $checkbox2, ..., $checkbox12). How can I make a While loop that iterates through a counter and reads the status of the checkbox which adds on that counter as part of the variable? Here is my proposed code attempt (just one of them, there have been many): $i = 1 While $i <= 12 If BitAND(GUICtrlRead("$checkbox" & $i), $GUI_CHECKED) = $GUI_CHECKED Then MsgBox(0,$i,"checked") EndIf WEnd The message box was just to see if I could cycle through the checkboxes, correctly. I know the If...Then statement works to tell me the status of $checkbox# if I statically call it $checkbox# but, again, that defeats the purpose of what I want to do. Any help or guidance would be greatly appreciated! If It's not possible then I will resort to the If...Then statements. Thanks, Matt
BrewManNH Posted November 25, 2014 Posted November 25, 2014 Use an array to hold the control IDs of the check boxes instead of a simple variable. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! Reveal hidden contents I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
ubelong2matt Posted November 25, 2014 Author Posted November 25, 2014 So, basically, hard-code the array with my $checkbox1-12 and then iterate through that?
BrewManNH Posted November 25, 2014 Posted November 25, 2014 Something like this. GUICreate("Test") Global $aCheckbox[5] For $I = 0 to 4 $aCheckbox[$i] = GUICtrlCreateCheckbox("Checkbox" & $I , 40, 10 + (30 * $I)) Next GUISetState() While GUIGetMsg()<> -3 sleep(10) wend Pretend there's no magic numbers in it. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! Reveal hidden contents I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
ubelong2matt Posted November 25, 2014 Author Posted November 25, 2014 Unfortunately, that is not what I mean. I am not looking to create the checkboxes with counting numbers at the end, which is what I found when Google searching this problem. The checkboxes have already been statically created with values and set to be checked. The idea is that the user can uncheck them if they want. I want to see which ones are checked and figure out what to do. This involves using a GUICtrlRead($checkbox#). The # in that previous example is what needs to change for each iteration. The problem is that it doesn't think "$checkbox" & $i is a variable but thinks of it as a string. Here is the code. The specific function is the _AddExceptions() function: expandcollapse popup#include <File.au3> #include "JavaGUI.au3" Global $javaVersion = FileGetVersion("java.exe") Global $parseJavaVersion = StringSplit($JavaVersion, ".") Global $javaRoot = $parseJavaVersion[1] Global $javaUpdate = $parseJavaVersion[3] Global $appData = @UserProfileDir & "\AppData\LocalLow\Sun\Java\Deployment\security" Global $exceptionFile = $appData & "\exception.sites" Global $exceptionFileContent = FileRead($exceptionFile) _GUI() Func _GUI() If (_FindJavaVersion($javaRoot, $javaUpdate) == 1) Then _ErrorMessages(1) Else GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $buttonAdd _AddSite(GUICtrlRead($inputAdditionalSites)) Case $buttonRemove _RemoveSite(_GUICtrlListBox_GetCaretIndex($listAdditionalSites)) Case $buttonCancel Exit Case $buttonSubmitChanges ;~ _CheckForFile($exceptionFile) _AddExceptions() EndSwitch WEnd EndIf EndFunc Func _AddSite($site) If (_IsValidURL($site) == 1) Then _ErrorMessages(2) Else GUICtrlSetData($listAdditionalSites, $site) EndIf EndFunc Func _RemoveSite($site) _GUICtrlListBox_DeleteString($listAdditionalSites, $site) EndFunc Func _CheckForFile($file) If Not FileExists($file) Then _FileCreate($file) EndIf EndFunc Func _AddExceptions() Local $aArrayOfCheckBoxes[12] = [GUICtrlRead($checkbox1), GUICtrlRead($checkbox2), GUICtrlRead($checkbox3), GUICtrlRead($checkbox4), GUICtrlRead($checkbox5), GUICtrlRead($checkbox6), _ GUICtrlRead($checkbox7), GUICtrlRead($checkbox8), GUICtrlRead($checkbox9), GUICtrlRead($checkbox10), GUICtrlRead($checkbox11), GUICtrlRead($checkbox12)] For $i = 0 to UBound($aArrayOfCheckBoxes) - 1 Next EndFunc Func _ExistingExceptionCheck($url) If Not StringInStr($exceptionFileContent, $url) Then FileWriteLine($exceptionFile, $url) Return 0 Else Return 1 EndIf EndFunc ;* ;* _FindJavaVersion ;* Helper method to test for the proper Java version based on what ;* we determine the user's Java version to be. ;* ;* @param $root - Java version (i.e. 7 or 8) ;* @param $version - Java sub-versioning (i.e. 51, 510, etc.) ;* @return 0 for a good version detected ;* 1 for a bad version detected ;* Func _FindJavaVersion($root, $version) If ($root < 7 And $version < 510) Then Return 1 EndIf EndFunc ;* ;* _IsValidURL ;* Helper method to check if a valid URL was provided. ;* Credit to JScript - Snippet Version No. = 1.0 ;* Snippet was Created Using AutoIt Version = 3.3.8.1, Creation Date = 22/05/12. ;* ;* @param $path - URL path ;* @return 0 for a good URL ;* 1 for a bad URL ;* Func _IsValidURL($path) Local $pattern = "(\W|^)(http|https)(://).*" Local $url = StringSplit($path, "://", 1) If (Not StringRegExp($path, $pattern) Or Ping($url[2],10) <= 0) Then Return 1 EndIf EndFunc ;* ;* _ErrorMessages ;* Helper method to provide us with canned error messages. ;* ;* @param $i - number of message to select ;* @return na ;* Func _ErrorMessages($i) Switch $i Case 1 MsgBox(16, "Java 7u51+ Not Found", "Java version 7 update 51 or higher is needed to run this program." & @CRLF & @CRLF & "The currently detected version is " & $javaRoot & "u" & $javaUpdate & ". Please go to java.com and update Java to version 7u51 or higher and re-run this program.", 0, $formJavaSecurityFix) Exit Case 2 MsgBox(48, "Invalid URL", "The URL you entered was empty, not properly formatted, or uses the wrong protocol." & @CRLF & @CRLF & "Please enter the URL in the format of:" & @CRLF & @TAB & "http://www.example.com" & @CRLF & @TAB & "https://example.net", 0, $formJavaSecurityFix) EndSwitch EndFunc GUI Code: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=c:\users\mjhelto\desktop\java security fix 3.kxf $windowWidth = 528 $windowHeight = 554 $formJavaSecurityFix = GUICreate("Java Security Fix 3.0", $windowWidth, $windowHeight, @DesktopWidth / 2 - $windowWidth / 2, @DesktopHeight / 2 - $windowHeight / 2) $groupStep1 = GUICtrlCreateGroup("Step 1", 8, 0, 512, 193) GUICtrlSetFont(-1, 10, 800, 0, "Lucida Sans Unicode") $checkbox1 = GUICtrlCreateCheckbox("http://tv.ilstu.edu", 16, 48, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "On-campus TV site.") $checkbox2 = GUICtrlCreateCheckbox("http://tv.illinoisstate.edu", 16, 72, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "On-campus TV site.") $checkbox3 = GUICtrlCreateCheckbox("http://138.87.84.61", 16, 96, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Site for TV streaming.") $checkbox4 = GUICtrlCreateCheckbox("https://webvpn.ilstu.edu", 16, 120, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "WebVPNs network connect client.") $checkbox5 = GUICtrlCreateCheckbox("https://webvpn.illinoisstate.edu", 16, 144, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "WebVPN's network connect client.") $checkbox6 = GUICtrlCreateCheckbox("https://vpn01.ilstu.edu", 16, 168, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Cisco AnyConnect VPN site.") $checkbox7 = GUICtrlCreateCheckbox("https://vpn01.illinoisstate.edu", 272, 48, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Cisco AnyConnect VPN site.") $checkbox8 = GUICtrlCreateCheckbox("https://reggienet.ilstu.edu", 272, 72, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Reggienet.") $checkbox9 = GUICtrlCreateCheckbox("https://reggienet.illinoisstate.edu", 272, 96, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Reggienet.") $checkbox10 = GUICtrlCreateCheckbox("http://ndt.ilstu.edu:7123", 272, 120, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Network Diagnostic Test site.") $checkbox11 = GUICtrlCreateCheckbox("http://helpdesk.ilstu.edu", 272, 144, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Helpdesk site.") $checkbox12 = GUICtrlCreateCheckbox("http://helpdesk.illinoisstate.edu", 272, 168, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Helpdesk site.") $labelStep1Explanation = GUICtrlCreateLabel("Pick the ISU websites you would like to have added to the exception.sites file.", 16, 24, 494, 20) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlCreateGroup("", -99, -99, 1, 1) $groupStep2 = GUICtrlCreateGroup("Step 2 (Optional)", 8, 200, 513, 241) GUICtrlSetFont(-1, 10, 800, 0, "Lucida Sans Unicode") $labelStep2Explanation = GUICtrlCreateLabel("Enter any additional exceptions you would like to add and then click ADD.", 16, 224, 472, 20) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") $inputAdditionalSites = GUICtrlCreateInput("", 16, 248, 249, 24) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "https://www.example.com") $listAdditionalSites = GUICtrlCreateList("", 304, 248, 201, 134) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") $buttonAdd = GUICtrlCreateButton("ADD", 80, 280, 123, 33) GUICtrlSetFont(-1, 12, 400, 0, "Lucida Sans Unicode") $buttonRemove = GUICtrlCreateButton("REMOVE", 352, 392, 107, 41) GUICtrlSetFont(-1, 12, 400, 0, "Lucida Sans Unicode") $labelRemoveExplanation = GUICtrlCreateLabel("Highlight the row you want to remove and click", 40, 408, 303, 20) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlCreateGroup("", -99, -99, 1, 1) $groupStep3 = GUICtrlCreateGroup("Step 3", 7, 448, 513, 97) GUICtrlSetFont(-1, 10, 800, 0, "Lucida Sans Unicode") $labelStep3Explanation = GUICtrlCreateLabel("Ensure your changes are correct and then click SUBMIT to commit.", 15, 472, 421, 20) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") $buttonSubmitChanges = GUICtrlCreateButton("SUBMIT", 55, 496, 163, 33) GUICtrlSetFont(-1, 12, 400, 0, "Lucida Sans Unicode") $buttonCancel = GUICtrlCreateButton("CANCEL", 367, 496, 83, 33) GUICtrlSetFont(-1, 12, 400, 0, "Lucida Sans Unicode") GUICtrlCreateGroup("", -99, -99, 1, 1) #EndRegion ### END Koda GUI section ###
Solution BrewManNH Posted November 26, 2014 Solution Posted November 26, 2014 Try it this way, modified your script to use an array, this one is a 2D array, the array $aArrayOfCheckboxes[n][0] holds the checkbox control ID and the state of it, it's initially set to a state of 0. In the _AddExceptions function it sets the second dimension of each array element to whatever GUICtrlRead returns. expandcollapse popup#Tidy_Parameters=/sf #include <File.au3> #include "JavaGUI.au3" #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $javaVersion = FileGetVersion("java.exe") Global $parseJavaVersion = StringSplit($javaVersion, ".") Global $javaRoot = $parseJavaVersion[1] Global $javaUpdate = $parseJavaVersion[3] Global $appData = @UserProfileDir & "\AppData\LocalLow\Sun\Java\Deployment\security" Global $exceptionFile = $appData & "\exception.sites" Global $exceptionFileContent = FileRead($exceptionFile) Global $aArrayOfCheckBoxes[12][1] = [[9999,0], [9999,0],[9999,0],[9999,0],[9999,0],[9999,0],[9999,0],[9999,0],[9999,0],[9999,0],[9999,0],[9999,0],[9999,0]] _GUI() $windowWidth = 528 $windowHeight = 554 $formJavaSecurityFix = GUICreate("Java Security Fix 3.0", $windowWidth, $windowHeight, @DesktopWidth / 2 - $windowWidth / 2, @DesktopHeight / 2 - $windowHeight / 2) $groupStep1 = GUICtrlCreateGroup("Step 1", 8, 0, 512, 193) GUICtrlSetFont(-1, 10, 800, 0, "Lucida Sans Unicode") $aArrayOfCheckBoxes[1][0] = GUICtrlCreateCheckbox("http://tv.ilstu.edu", 16, 48, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "On-campus TV site.") $aArrayOfCheckBoxes[2][0] = GUICtrlCreateCheckbox("http://tv.illinoisstate.edu", 16, 72, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "On-campus TV site.") $aArrayOfCheckBoxes[3][0] = GUICtrlCreateCheckbox("http://138.87.84.61", 16, 96, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Site for TV streaming.") $aArrayOfCheckBoxes[4][0] = GUICtrlCreateCheckbox("https://webvpn.ilstu.edu", 16, 120, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "WebVPNs network connect client.") $aArrayOfCheckBoxes[5][0] = GUICtrlCreateCheckbox("https://webvpn.illinoisstate.edu", 16, 144, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "WebVPN's network connect client.") $aArrayOfCheckBoxes[6][0] = GUICtrlCreateCheckbox("https://vpn01.ilstu.edu", 16, 168, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Cisco AnyConnect VPN site.") $aArrayOfCheckBoxes[7][0] = GUICtrlCreateCheckbox("https://vpn01.illinoisstate.edu", 272, 48, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Cisco AnyConnect VPN site.") $aArrayOfCheckBoxes[8][0] = GUICtrlCreateCheckbox("https://reggienet.ilstu.edu", 272, 72, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Reggienet.") $aArrayOfCheckBoxes[9][0] = GUICtrlCreateCheckbox("https://reggienet.illinoisstate.edu", 272, 96, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Reggienet.") $aArrayOfCheckBoxes[10][0] = GUICtrlCreateCheckbox("http://ndt.ilstu.edu:7123", 272, 120, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Network Diagnostic Test site.") $aArrayOfCheckBoxes[11][0] = GUICtrlCreateCheckbox("http://helpdesk.ilstu.edu", 272, 144, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Helpdesk site.") $aArrayOfCheckBoxes[12][0] = GUICtrlCreateCheckbox("http://helpdesk.illinoisstate.edu", 272, 168, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Helpdesk site.") $labelStep1Explanation = GUICtrlCreateLabel("Pick the ISU websites you would like to have added to the exception.sites file.", 16, 24, 494, 20) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlCreateGroup("", -99, -99, 1, 1) $groupStep2 = GUICtrlCreateGroup("Step 2 (Optional)", 8, 200, 513, 241) GUICtrlSetFont(-1, 10, 800, 0, "Lucida Sans Unicode") $labelStep2Explanation = GUICtrlCreateLabel("Enter any additional exceptions you would like to add and then click ADD.", 16, 224, 472, 20) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") $inputAdditionalSites = GUICtrlCreateInput("", 16, 248, 249, 24) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "https://www.example.com") $listAdditionalSites = GUICtrlCreateList("", 304, 248, 201, 134) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") $buttonAdd = GUICtrlCreateButton("ADD", 80, 280, 123, 33) GUICtrlSetFont(-1, 12, 400, 0, "Lucida Sans Unicode") $buttonRemove = GUICtrlCreateButton("REMOVE", 352, 392, 107, 41) GUICtrlSetFont(-1, 12, 400, 0, "Lucida Sans Unicode") $labelRemoveExplanation = GUICtrlCreateLabel("Highlight the row you want to remove and click", 40, 408, 303, 20) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlCreateGroup("", -99, -99, 1, 1) $groupStep3 = GUICtrlCreateGroup("Step 3", 7, 448, 513, 97) GUICtrlSetFont(-1, 10, 800, 0, "Lucida Sans Unicode") $labelStep3Explanation = GUICtrlCreateLabel("Ensure your changes are correct and then click SUBMIT to commit.", 15, 472, 421, 20) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") $buttonSubmitChanges = GUICtrlCreateButton("SUBMIT", 55, 496, 163, 33) GUICtrlSetFont(-1, 12, 400, 0, "Lucida Sans Unicode") $buttonCancel = GUICtrlCreateButton("CANCEL", 367, 496, 83, 33) GUICtrlSetFont(-1, 12, 400, 0, "Lucida Sans Unicode") GUICtrlCreateGroup("", -99, -99, 1, 1) Func _AddExceptions() For $i = 0 To UBound($aArrayOfCheckBoxes) - 1 $aArrayOfCheckBoxes[$I][0] = GUICtrlRead($aArrayOfCheckBoxes) Next EndFunc ;==>_AddExceptions Func _AddSite($site) If (_IsValidURL($site) == 1) Then _ErrorMessages(2) Else GUICtrlSetData($listAdditionalSites, $site) EndIf EndFunc ;==>_AddSite Func _CheckForFile($file) If Not FileExists($file) Then _FileCreate($file) EndIf EndFunc ;==>_CheckForFile ;* ;* _ErrorMessages ;* Helper method to provide us with canned error messages. ;* ;* @param $i - number of message to select ;* @return na ;* Func _ErrorMessages($i) Switch $i Case 1 MsgBox(16, "Java 7u51+ Not Found", "Java version 7 update 51 or higher is needed to run this program." & @CRLF & @CRLF & "The currently detected version is " & $javaRoot & "u" & $javaUpdate & ". Please go to java.com and update Java to version 7u51 or higher and re-run this program.", 0, $formJavaSecurityFix) Exit Case 2 MsgBox(48, "Invalid URL", "The URL you entered was empty, not properly formatted, or uses the wrong protocol." & @CRLF & @CRLF & "Please enter the URL in the format of:" & @CRLF & @TAB & "http://www.example.com" & @CRLF & @TAB & "https://example.net", 0, $formJavaSecurityFix) EndSwitch EndFunc ;==>_ErrorMessages Func _ExistingExceptionCheck($url) If Not StringInStr($exceptionFileContent, $url) Then FileWriteLine($exceptionFile, $url) Return 0 Else Return 1 EndIf EndFunc ;==>_ExistingExceptionCheck ;* ;* _FindJavaVersion ;* Helper method to test for the proper Java version based on what ;* we determine the user's Java version to be. ;* ;* @param $root - Java version (i.e. 7 or 8) ;* @param $version - Java sub-versioning (i.e. 51, 510, etc.) ;* @return 0 for a good version detected ;* 1 for a bad version detected ;* Func _FindJavaVersion($root, $version) If ($root < 7 And $version < 510) Then Return 1 EndIf EndFunc ;==>_FindJavaVersion Func _GUI() If (_FindJavaVersion($javaRoot, $javaUpdate) == 1) Then _ErrorMessages(1) Else GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $buttonAdd _AddSite(GUICtrlRead($inputAdditionalSites)) Case $buttonRemove _RemoveSite(_GUICtrlListBox_GetCaretIndex($listAdditionalSites)) Case $buttonCancel Exit Case $buttonSubmitChanges ;~ _CheckForFile($exceptionFile) _AddExceptions() EndSwitch WEnd EndIf EndFunc ;==>_GUI ;* ;* _IsValidURL ;* Helper method to check if a valid URL was provided. ;* Credit to JScript - Snippet Version No. = 1.0 ;* Snippet was Created Using AutoIt Version = 3.3.8.1, Creation Date = 22/05/12. ;* ;* @param $path - URL path ;* @return 0 for a good URL ;* 1 for a bad URL ;* Func _IsValidURL($path) Local $pattern = "(\W|^)(http|https)(://).*" Local $url = StringSplit($path, "://", 1) If (Not StringRegExp($path, $pattern) Or Ping($url[2], 10) <= 0) Then Return 1 EndIf EndFunc ;==>_IsValidURL Func _RemoveSite($site) _GUICtrlListBox_DeleteString($listAdditionalSites, $site) EndFunc ;==>_RemoveSite If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! Reveal hidden contents I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
ubelong2matt Posted November 26, 2014 Author Posted November 26, 2014 There were some minor errors in your code that I had to change but I was able to adapt it, I think. We'll find out last today when, I hope, I finish the program! I appreciate your help, BrewManNH!
BrewManNH Posted November 26, 2014 Posted November 26, 2014 Yeah, it was a concept script because I couldn't run yours as it was written, but I hope I got the general idea across. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! Reveal hidden contents I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
ubelong2matt Posted November 27, 2014 Author Posted November 27, 2014 BrewManNH, you're great. I managed to get my program running flawlessly and I couldn't have done that without your help. My completed script is below. Java Security Fix v3.0: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=favicon.ico #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;*********************************************************************************************************** ;* Program: Java Security Fix * ;* Version: 3.0 * ;* Date: 11/26/14 * ;* Purpose: To add ISU websites, and user specified sites, using Java applets to the Java exception list. * ;* Application: Only applies to Java 7u51 or higher. * ;* Author: Matt * ;* Special Thanks: mLipok and BrewManNH from the Autoit Community * ;* Company: Illinois State University * ;* License: GNU GPL * ;*********************************************************************************************************** #include <File.au3> ;UDF that handles file manipulation #include "JavaGUI.au3" ;GUI ;global variable(s) Global $javaVersion = FileGetVersion("java.exe") ;version of Java that exists on the machine Global $parseJavaVersion = StringSplit($JavaVersion, ".") ;parse out the java version as they do not come in the format we need Global $javaRoot = $parseJavaVersion[1] ;pull the version out (i.e. 7, 8, and etc.) Global $javaUpdate = $parseJavaVersion[3] ;pull out the sub-version or update version (i.e. 57, 510, etc.) Global $appData = @UserProfileDir & "\AppData\LocalLow\Sun\Java\Deployment\security" ;location of our exception file Global $exceptionFile = $appData & "\exception.sites" ;exception file's name Global $actionsPerformed = "" ;blank string that will hold what was done Global $counter = 1 ;counter to keep track of how many steps have been performed _GUI() ;run GUI function ;* ;* _AddException ;* Builds an array of ISU sites and checks if a user added their own sites ;* and adds those. It them looks at the checkboxes that remained checked ;* and adds those, also. ;* ;* @param na ;* @return na ;* Func _AddExceptions() ;local variable(s) Local $listOfURLs[12] = ["http://tv.ilstu.edu", "http://tv.illinoisstate.edu", "http://138.87.84.61", "https://webvpn.ilstu.edu", "https://webvpn.illinoisstate.edu", _ "https://vpn01.ilstu.edu", "https://vpn01.illinoisstate.edu", "https://reggienet.ilstu.edu", "https://reggienet.illinoisstate.edu", "http://ndt.ilstu.edu:7123", _ "http://helpdesk.ilstu.edu", "http://helpdesk.illinoisstate.edu"] Local $numOfListItems = _GUICtrlListBox_GetCount($listAdditionalSites) ;look at and process checked checkboxes For $i = 0 To UBound($aArrayOfCheckBoxes) - 1 $checkedStatus = GUICtrlRead($aArrayOfCheckBoxes[$i][0]) If $checkedStatus == 1 Then _ExistingExceptionCheck($listOfURLs[$i]) Else $actionsPerformed = $actionsPerformed & $counter & ") " & $listOfURLs[$i] & " was not checked." & @CRLF $counter += 1 EndIf Next ;check for user-supplied URLs If $numOfListItems <> 0 Then For $i = 0 To $numOfListItems - 1 _ExistingExceptionCheck(_GUICtrlListBox_GetText($listAdditionalSites, $i)) Next $actionsPerformed = $actionsPerformed & $counter & ") Completed checking for user-supplied websites." & @CRLF $counter += 1 EndIf EndFunc ;==>_AddExceptions ;* ;* _AddSite ;* Adds the provided site to the list of user-supplied ;* sites to add to the exception file. ;* ;* @param $site - Site to add to the list ;* @return na ;* Func _AddSite($site) ;not a valid URL will display an error message If (_IsValidURL($site) == 1) Then _ErrorMessages(2) Else ;add site to list, clear the list, and set focus back to the input field GUICtrlSetData($listAdditionalSites, $site) GUICtrlSetData($inputAdditionalSites, "") GUICtrlSetState($inputAdditionalSites, $GUI_FOCUS) $actionsPerformed = $actionsPerformed & $counter & ") Added " & $site & " to the list of user-supplied sites." & @CRLF $counter += 1 EndIf EndFunc ;==>_AddSite ;* ;* _CheckForFile ;* Checks for the existance of the exception.sites file and if it ;* doesn't exist it will create it. ;* ;* @param $file - The file to check for. ;* @return na ;* Func _CheckForFile($file) ;doesn't exist then make it If Not FileExists($file) Then _FileCreate($file) $actionsPerformed = $actionsPerformed & $counter & ") Exception file did not exist so it was created." & @CRLF $counter += 1 Else ;otherwise just carry on $actionsPerformed = $actionsPerformed & $counter & ") Exception file already exists." & @CRLF $counter += 1 EndIf EndFunc ;==>_CheckForFile ;* ;* _ErrorMessages ;* Helper method to provide us with canned error messages. ;* ;* @param $i - number of message to select ;* @return na ;* Func _ErrorMessages($i) Switch $i Case 1 ;for bad Java version MsgBox(16, "Java 7u51+ Not Found", "Java version 7 update 51 or higher is needed to run this program." & @CRLF & @CRLF & "The currently detected version is " & $javaRoot & "u" & $javaUpdate & ". Please go to java.com and update Java to version 7u51 or higher and re-run this program.", 0, $formJavaSecurityFix) Exit Case 2 ;for bad URL MsgBox(48, "Invalid URL", "The URL you entered was empty, not properly formatted, or uses the wrong protocol." & @CRLF & @CRLF & "Please enter the URL in the format of:" & @CRLF & @TAB & "http://www.example.com" & @CRLF & @TAB & "https://example.net", 0, $formJavaSecurityFix) EndSwitch EndFunc ;==>_ErrorMessages ;* ;* _ExistingExceptionCheck ;* Reads the exception file and checks if a supplied exception already ;* exists in the file and if it doesn't, adds it to the exception file ;* then closes the file. ;* ;* @param $url - The URL to check for ;* @return na ;* Func _ExistingExceptionCheck($url) ;if the exception doesn't exist then add it If Not StringInStr(FileRead($exceptionFile), $url) Then FileWriteLine($exceptionFile, $url) FileClose($exceptionFile) $actionsPerformed = $actionsPerformed & $counter & ") " & $url & " was added to the exception file." & @CRLF $counter += 1 Else ;if it does then just close the file FileClose($exceptionFile) $actionsPerformed = $actionsPerformed & $counter & ") " & $url & " was already in the exception file." & @CRLF $counter += 1 EndIf EndFunc ;==>_ExistingExceptionCheck ;* ;* _FindJavaVersion ;* Helper method to test for the proper Java version based on what ;* we determine the user's Java version to be. ;* ;* @param $root - Java version (i.e. 7 or 8) ;* @param $version - Java sub-versioning (i.e. 51, 510, etc.) ;* @return 0 for a good version detected ;* 1 for a bad version detected ;* Func _FindJavaVersion($root, $version) ;if the Java version is below 7u51 the display an error message If ($root < 7 And $version < 510) Then Return 1 Else ;otherwise just carry on $actionsPerformed = $actionsPerformed & $counter & ") Java version " & $root & "u" & $version & " of Java was found on the computer." & @CRLF $counter += 1 EndIf EndFunc ;==>_FindJavaVersion ;* ;* _GUI ;* Checks Java version and if it is high enough, displays the GUI ;* and awaits changes to it by listening to various changes. ;* ;* @param na ;* @return na ;* Func _GUI() ;if the version is wrong then error and kill the program If (_FindJavaVersion($javaRoot, $javaUpdate) == 1) Then _ErrorMessages(1) Else ;disiplay the GUI and listen for changes GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ;clicking the "red X" Exit Case $buttonAdd ;clicking the ADD button _AddSite(GUICtrlRead($inputAdditionalSites)) Case $buttonRemove ;clicking the REMOVE button _RemoveSite(_GUICtrlListBox_GetCaretIndex($listAdditionalSites)) Case $buttonCancel ;clicking the CANCEL button Exit Case $buttonSubmitChanges ;clicking the SUBMIT button _CheckForFile($exceptionFile) _AddExceptions() MsgBox(0,"Operation Complete", "Outcome of operation:" & @CRLF & @CRLF & $actionsPerformed, 0, $formJavaSecurityFix) ;this displays the actions that were performed during operation Exit EndSwitch WEnd EndIf EndFunc ;==>_GUI ;* ;* _IsValidURL ;* Helper method to check if a valid URL was provided. ;* Credit to JScript - Snippet Version No. = 1.0 ;* Snippet was Created Using AutoIt Version = 3.3.8.1, Creation Date = 22/05/12. ;* ;* @param $path - URL path ;* @return 0 for a good URL ;* 1 for a bad URL ;* Func _IsValidURL($path) ;local variable(s) Local $pattern = "(\W|^)(http|https)(://).*" ;if the provided URL doesn't match our pattern then return a 1 for an error If (Not StringRegExp($path, $pattern)) Then Return 1 EndIf EndFunc ;==>_IsValidURL ;* ;* _RemoveSite ;* Removes a selected site, or the last site, from the list ;* of user-supplied sites to add. ;* ;* @param $site - The site to remove. ;* @return na ;* Func _RemoveSite($site) ;remove the selected site or whatever is at the bottom of the list if no site is selected _GUICtrlListBox_DeleteString($listAdditionalSites, $site) $actionsPerformed = $actionsPerformed & $counter & ") Removed " & $site & " from the list of user-supplied sites." & @CRLF $counter += 1 EndFunc ;==>_RemoveSite JavaGUI.au3 expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $aArrayOfCheckBoxes[12][2] = [[9999,0],[9999,0],[9999,0],[9999,0],[9999,0],[9999,0],[9999,0],[9999,0],[9999,0],[9999,0],[9999,0],[9999,0]] Local $windowWidth = 528 Local $windowHeight = 554 #Region ### START Koda GUI section ### Form=c:\users\mjhelto\desktop\java security fix 3.kxf $formJavaSecurityFix = GUICreate("Java Security Fix 3.0", $windowWidth, $windowHeight, @DesktopWidth / 2 - $windowWidth / 2, @DesktopHeight / 2 - $windowHeight / 2) $groupStep1 = GUICtrlCreateGroup("Step 1", 8, 0, 512, 193) GUICtrlSetFont(-1, 10, 800, 0, "Lucida Sans Unicode") $aArrayOfCheckBoxes[0][0] = GUICtrlCreateCheckbox("http://tv.ilstu.edu", 16, 48, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "On-campus TV site.") $aArrayOfCheckBoxes[1][0] = GUICtrlCreateCheckbox("http://tv.illinoisstate.edu", 16, 72, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "On-campus TV site.") $aArrayOfCheckBoxes[2][0] = GUICtrlCreateCheckbox("http://138.87.84.61", 16, 96, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Site for TV streaming.") $aArrayOfCheckBoxes[3][0] = GUICtrlCreateCheckbox("https://webvpn.ilstu.edu", 16, 120, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "WebVPNs network connect client.") $aArrayOfCheckBoxes[4][0] = GUICtrlCreateCheckbox("https://webvpn.illinoisstate.edu", 16, 144, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "WebVPN's network connect client.") $aArrayOfCheckBoxes[5][0] = GUICtrlCreateCheckbox("https://vpn01.ilstu.edu", 16, 168, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Cisco AnyConnect VPN site.") $aArrayOfCheckBoxes[6][0] = GUICtrlCreateCheckbox("https://vpn01.illinoisstate.edu", 272, 48, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Cisco AnyConnect VPN site.") $aArrayOfCheckBoxes[7][0] = GUICtrlCreateCheckbox("https://reggienet.ilstu.edu", 272, 72, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Reggienet.") $aArrayOfCheckBoxes[8][0] = GUICtrlCreateCheckbox("https://reggienet.illinoisstate.edu", 272, 96, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Reggienet.") $aArrayOfCheckBoxes[9][0] = GUICtrlCreateCheckbox("http://ndt.ilstu.edu:7123", 272, 120, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Network Diagnostic Test site.") $aArrayOfCheckBoxes[10][0] = GUICtrlCreateCheckbox("http://helpdesk.ilstu.edu", 272, 144, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Helpdesk site.") $aArrayOfCheckBoxes[11][0] = GUICtrlCreateCheckbox("http://helpdesk.illinoisstate.edu", 272, 168, 235, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "Helpdesk site.") $labelStep1Explanation = GUICtrlCreateLabel("Pick the ISU websites you would like to have added to the exception.sites file.", 16, 24, 494, 20) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") $groupStep2 = GUICtrlCreateGroup("Step 2 (Optional)", 8, 200, 513, 241) GUICtrlSetFont(-1, 10, 800, 0, "Lucida Sans Unicode") $labelStep2Explanation = GUICtrlCreateLabel("Enter any additional exceptions you would like to add and then click ADD.", 16, 224, 472, 20) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") $inputAdditionalSites = GUICtrlCreateInput("", 16, 248, 249, 24) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") GUICtrlSetTip(-1, "https://www.example.com") $listAdditionalSites = GUICtrlCreateList("", 304, 248, 201, 134) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") $buttonAdd = GUICtrlCreateButton("ADD", 80, 280, 123, 33) GUICtrlSetFont(-1, 12, 400, 0, "Lucida Sans Unicode") $buttonRemove = GUICtrlCreateButton("REMOVE", 352, 392, 107, 41) GUICtrlSetFont(-1, 12, 400, 0, "Lucida Sans Unicode") $labelRemoveExplanation = GUICtrlCreateLabel("Highlight the row you want to remove and click", 40, 408, 303, 20) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") $groupStep3 = GUICtrlCreateGroup("Step 3", 7, 448, 513, 97) GUICtrlSetFont(-1, 10, 800, 0, "Lucida Sans Unicode") $labelStep3Explanation = GUICtrlCreateLabel("Ensure your changes are correct and then click SUBMIT to commit.", 15, 472, 421, 20) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Sans Unicode") $buttonSubmitChanges = GUICtrlCreateButton("SUBMIT", 55, 496, 163, 33) GUICtrlSetFont(-1, 12, 400, 0, "Lucida Sans Unicode") $buttonCancel = GUICtrlCreateButton("CANCEL", 367, 496, 83, 33) GUICtrlSetFont(-1, 12, 400, 0, "Lucida Sans Unicode") #EndRegion ### END Koda GUI section ###
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