chaitukch Posted September 7, 2007 Share Posted September 7, 2007 (edited) Hi, I am new to Autoit. I have been using it from just 3 days and started creating a GUI for automating installtion of apps. It will have a list of apps and will install only the apps that have been checked. I have created a treeview with checkboxes. But cant figure out how to get the apps installed. Please help me out with this. I have googled for some codes and with the help of them and help file from autoit I have created a small GUI, the code of which is below. Please some one help me out to complete this. Thanks in advance. expandcollapse popupdim $APP1_CHKBOX dim $APP2_CHKBOX dim $APP3_CHKBOX dim $APP4_CHKBOX dim $APP5_CHKBOX dim $APP6_CHKBOX dim $APP7_CHKBOX dim $APP8_CHKBOX dim $APP9_CHKBOX dim $APP10_CHKBOX dim $RUN dim $EXIT dim $status1 dim $status2 dim $status3 dim $status4 dim $status5 dim $status6 dim $status7 dim $status8 dim $status9 dim $status10 #include <GUIConstants.au3> ;this is required for a GUI to work ;This creates the inital GUI box ;To Remove any non-needed checkboxes simply remark any of the CHKBOX lines GUICreate ("Application Launcher - 10 unit",580,400) GUISetFont(14,600) ; PIC GuiCtrlCreatePic("Logo.jpg",50,10,167,74) ;GuiCtrlCreateLabel("Sample pic", 75, 1, 53, 15) GuiCtrlSetColor(-1,0xffffff) ;Lable GUICtrlCreateLabel("Application Installer",240,20) GUICtrlCreateLabel("From folder",235,50) GUISetFont(9,400) ;TreeView $treeview = GUICtrlCreateTreeView(100, 120, 390, 200, BitOr($TVS_CHECKBOXES, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) $generalitem = GUICtrlCreateTreeViewitem("General", $treeview) GUICtrlSetColor(-1, 0x0000C0) $displayitem = GUICtrlCreateTreeViewitem("Display", $treeview) GUICtrlSetColor(-1, 0x0000C0) $APP1_CHKBOX = GUICtrlCreateTreeViewitem("Winrar", $generalitem) $APP2_CHKBOX = GUICtrlCreateTreeViewitem("Firefox", $generalitem);Checkbox 2 $APP3_CHKBOX = GUICtrlCreateTreeViewitem("Vim", $generalitem);Checkbox 3 $APP4_CHKBOX = GUICtrlCreateTreeViewitem("VLC", $generalitem);Checkbox 4 $APP5_CHKBOX = GUICtrlCreateTreeViewitem("Notepad ++", $generalitem);Checkbox 5 ;GUISetFont(9,400) ;$APP1_CHKBOX = GUICtrlCreateCheckbox("Win RAR",10,130);Checkbox 1 ;$APP1_CHKBOX = GUICtrlCreateCheckbox("Win RAR");Checkbox 1 ;$APP2_CHKBOX = GUICtrlCreateCheckbox("Firefox",10,150);Checkbox 2 ;$APP3_CHKBOX = GUICtrlCreateCheckbox("Vim",10,170);Checkbox 3 ;$APP4_CHKBOX = GUICtrlCreateCheckbox("VLC",10,190);Checkbox 4 ;$APP5_CHKBOX = GUICtrlCreateCheckbox("Notepad ++",10,210);Checkbox 5 $RUN = GUICtrlCreateButton("Install",10,350,120,20);This in the Run button $EXIT = GUICtrlCreateButton("Exit",450,350,120,20);This causes the application to exit GUISetState() Do $msg = GUIGetMsg() ;Reads the status of the Checkboxes and sets a variable to either 1 for checked or 4 for not checked ;This HAS to be included before the UNTIL statement $status1 = GUICtrlRead($APP1_CHKBOX) $status2 = GUICtrlRead($APP2_CHKBOX) $status3 = GUICtrlRead($APP3_CHKBOX) $status4 = GUICtrlRead($APP4_CHKBOX) $status5 = GUICtrlRead($APP5_CHKBOX) Until $msg = $EXIT or $msg = $RUN If $msg = $EXIT then Exit ;Checks the status of the Checkboxes and calls the application function(s) if the checkbox is enabled IF $status1 = 1 then call ("APP_1") IF $status2 = 1 then call ("APP_2") IF $status3 = 1 then call ("APP_3") IF $status4 = 1 then call ("APP_4") IF $status5 = 1 then call ("APP_5") Call ("END_APP") ;Add Application Functions here Func APP_1();Function for application 1 MsgBox(4096,"wrar370.exe","Installs Winrar") RunWait("wrar370.exe /S") EndFunc Func APP_2();Function for application 2 MsgBox(4096,"Firefox Setup 2.0.0.5.exe","Firefox") RunWait("Firefox Setup 2.0.0.5.exe") EndFunc Func APP_3();Function for application 3 MsgBox(4096,"gvim71.exe","Vim") RunWait("gvim71.exe") EndFunc Func APP_4();Function for application 4 MsgBox(4096,"vlc-0.8.6c-win32.exe","Vlc Player") RunWait("vlc-0.8.6c-win32.exe") EndFunc Func APP_5();Function for application 5 MsgBox(4096,"npp.4.2.2.Installer.exe","This is where Application 5 would run") RunWait("npp.4.2.2.Installer.exe") EndFunc Func END_APP() MsgBox(4096,"Complete","All Selected Applications Installed") EndFunc complete new code is also ok. ThanQ in advance once again Edited September 7, 2007 by chaitukch Link to comment Share on other sites More sharing options...
Siao Posted September 7, 2007 Share Posted September 7, 2007 (edited) One serious problem is that you don't take into acount that GUICtrlRead($treeviewitem) returns all states of that item. Checked is 1, but lets say if the item is checked and selected, it won't be 1 anymore. So you should really stick to Autoit helpfile and use BitAND method as shown in GUICtrlRead() description. Your main loop and the way you construct your app are unorthodox, some things are redundant (there's absolutely no need to continuously update $status variables in the main Do...Until loop, just a waste of CPU), but I guess it works... What exactly you mean by saying "cant figure out how to get the apps installed". Those RunWait should work fine provided that respective setup files are in the same directory as your script. Edited September 7, 2007 by Siao "be smart, drink your wine" Link to comment Share on other sites More sharing options...
chaitukch Posted September 7, 2007 Author Share Posted September 7, 2007 ThanQ very much for your reply Siao. Did u run the script that i have posted. When I run the script with a checkbox checked. It directly jumps and shows all applications installed.. and none of the app checked gets insalled. Can u run the given script and find me a solution. Thanks in advance Link to comment Share on other sites More sharing options...
DjDeep00 Posted September 7, 2007 Share Posted September 7, 2007 Straight from the help file.... (Just added the Checkbox style) This should get you going.... expandcollapse popup#include <GUIConstants.au3> GUICreate("My GUI with treeview", 350, 215) $treeview = GUICtrlCreateTreeView(6, 6, 100, 150, BitOr($TVS_CHECKBOXES, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) $generalitem = GUICtrlCreateTreeViewitem("General", $treeview) GUICtrlSetColor(-1, 0x0000C0) $displayitem = GUICtrlCreateTreeViewitem("Display", $treeview) GUICtrlSetColor(-1, 0x0000C0) $aboutitem = GUICtrlCreateTreeViewitem("About", $generalitem) $compitem = GUICtrlCreateTreeViewitem("Computer", $generalitem) $useritem = GUICtrlCreateTreeViewitem("User", $generalitem) $resitem = GUICtrlCreateTreeViewitem("Resolution", $displayitem) $otheritem = GUICtrlCreateTreeViewitem("Other", $displayitem) $startlabel = GUICtrlCreateLabel("TreeView Demo",190,90,100,20) $aboutlabel = GUICtrlCreateLabel("This little scripts demonstates the using of a treeview-control.", 190, 70, 100, 60) GUICtrlSetState(-1, $GUI_HIDE) ; Hides the "aboutlabel"-text during initialization $compinfo = GUICtrlCreateLabel("Name:" & @TAB & @ComputerName & @LF & "OS:" & @TAB & @OSVersion & @LF & "SP:" & @TAB & @OSServicePack, 120, 30, 200, 80) GUICtrlSetState(-1, $GUI_HIDE) ; Hides the "compinfo"-text during initialization GUICtrlCreateLabel("", 0, 170, 350, 2, $SS_SUNKEN) $togglebutton = GUICtrlCreateButton("&Toggle", 35, 185, 70, 20) $infobutton = GUICtrlCreateButton("&Info", 105, 185, 70, 20) $statebutton = GUICtrlCreateButton("Col./Exp.", 175, 185, 70, 20) $cancelbutton = GUICtrlCreateButton("&Cancel", 245, 185, 70, 20) GUICtrlSetState($generalitem, BitOr($GUI_EXPAND,$GUI_DEFBUTTON)) ; Expand the "General"-item and paint in bold GUICtrlSetState($displayitem, BitOr($GUI_EXPAND,$GUI_DEFBUTTON)) ; Expand the "Display"-item and paint in bold GUISetState () While 1 $msg = GUIGetMsg() Select Case $msg = $cancelbutton Or $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $togglebutton ; Toggle the bold painting If BitAnd(GUICtrlRead($generalitem), $GUI_DEFBUTTON) Then GUICtrlSetState($generalitem, 0) GUICtrlSetState($displayitem, 0) Else GUICtrlSetState($generalitem, $GUI_DEFBUTTON) GUICtrlSetState($displayitem, $GUI_DEFBUTTON) EndIf Case $msg = $infobutton $item = GUICtrlRead($treeview) ; Get the controlID of the current selected treeview item If $item = 0 Then MsgBox(64, "TreeView Demo", "No item currently selected") Else $text = GUICtrlRead($item, 1); Get the text of the treeview item If $text == "" Then MsgBox(16, "Error", "Error while retrieving infos about item") Else MsgBox(64, "TreeView Demo", "Current item selected is: " & $text) ; $advmsg[0] contains the text and $advmsg[1] the state value of the treeview item EndIf EndIf Case $msg = $statebutton $item = GUICtrlRead($treeview) If $item > 0 Then $hItem = GUICtrlGetHandle($item) GuiCtrlSendMsg($treeview, $TVM_EXPAND, $TVE_TOGGLE, $hItem) EndIf ; The following items will hide the other labels (1st and 2nd parameter) and then show the 'own' labels (3rd and 4th parameter) Case $msg = $generalitem GUIChangeItems($aboutlabel, $compinfo, $startlabel, $startlabel) Case $msg = $aboutitem GUICtrlSetState ($compinfo, $GUI_HIDE) GUIChangeItems($startlabel, $startlabel, $aboutlabel, $aboutlabel) Case $msg = $compitem GUIChangeItems($startlabel, $aboutlabel, $compinfo, $compinfo) EndSelect WEnd GUIDelete() Exit Func GUIChangeItems($hidestart, $hideend, $showstart, $showend) Local $idx For $idx = $hidestart To $hideend GUICtrlSetState ($idx, $GUI_HIDE) Next For $idx = $showstart To $showend GUICtrlSetState ($idx, $GUI_SHOW) Next EndFunc Link to comment Share on other sites More sharing options...
Zedna Posted September 7, 2007 Share Posted September 7, 2007 expandcollapse popup#include <GUIConstants.au3> ;this is required for a GUI to work ;This creates the inital GUI box ;To Remove any non-needed checkboxes simply remark any of the CHKBOX lines GUICreate ("Application Launcher - 10 unit",580,400) GUISetFont(14,600) ; PIC GuiCtrlCreatePic("Logo.jpg",50,10,167,74) ;GuiCtrlCreateLabel("Sample pic", 75, 1, 53, 15) GuiCtrlSetColor(-1,0xffffff) ;Lable GUICtrlCreateLabel("Application Installer",240,20) GUICtrlCreateLabel("From folder",235,50) GUISetFont(9,400) ;TreeView $treeview = GUICtrlCreateTreeView(100, 120, 390, 200, BitOr($TVS_CHECKBOXES, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) $generalitem = GUICtrlCreateTreeViewitem("General", $treeview) GUICtrlSetColor(-1, 0x0000C0) $displayitem = GUICtrlCreateTreeViewitem("Display", $treeview) GUICtrlSetColor(-1, 0x0000C0) $APP1_CHKBOX = GUICtrlCreateTreeViewitem("Winrar", $generalitem) $APP2_CHKBOX = GUICtrlCreateTreeViewitem("Firefox", $generalitem);Checkbox 2 $APP3_CHKBOX = GUICtrlCreateTreeViewitem("Vim", $generalitem);Checkbox 3 $APP4_CHKBOX = GUICtrlCreateTreeViewitem("VLC", $generalitem);Checkbox 4 $APP5_CHKBOX = GUICtrlCreateTreeViewitem("Notepad ++", $generalitem);Checkbox 5 $RUN = GUICtrlCreateButton("Install",10,350,120,20);This in the Run button $EXIT = GUICtrlCreateButton("Exit",450,350,120,20);This causes the application to exit GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $EXIT Exit Case $msg = $RUN Install() EndSelect WEnd Exit Func IsChecked($control) Return BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED EndFunc Func Install() ;Checks the status of the Checkboxes and calls the application function(s) if the checkbox is enabled IF IsChecked($APP1_CHKBOX) then APP_1() IF IsChecked($APP2_CHKBOX) then APP_2() IF IsChecked($APP3_CHKBOX) then APP_3() IF IsChecked($APP4_CHKBOX) then APP_4() IF IsChecked($APP5_CHKBOX) then APP_5() MsgBox(4096,"Complete","All Selected Applications Installed") Exit EndFunc ;Add Application Functions here Func APP_1();Function for application 1 MsgBox(4096,"wrar370.exe","Installs Winrar") RunWait("wrar370.exe /S") EndFunc Func APP_2();Function for application 2 MsgBox(4096,"Firefox Setup 2.0.0.5.exe","Firefox") RunWait("Firefox Setup 2.0.0.5.exe") EndFunc Func APP_3();Function for application 3 MsgBox(4096,"gvim71.exe","Vim") RunWait("gvim71.exe") EndFunc Func APP_4();Function for application 4 MsgBox(4096,"vlc-0.8.6c-win32.exe","Vlc Player") RunWait("vlc-0.8.6c-win32.exe") EndFunc Func APP_5();Function for application 5 MsgBox(4096,"npp.4.2.2.Installer.exe","This is where Application 5 would run") RunWait("npp.4.2.2.Installer.exe") EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
chaitukch Posted September 7, 2007 Author Share Posted September 7, 2007 You are my saviour ZEDNA. ThanQ ThanQ very much for the code. It works Exactly as I needed it. ThanQ ThanQ very much Link to comment Share on other sites More sharing options...
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