Jump to content

Recommended Posts

Posted

Is it possible to have a GUI with multiple check boxes so that each box that is checked could perform a unique function?

Goal: I would like to have 8 check boxes and, depending on which ones are checked, each checked box will invoke a seperate routine

Layout:

|x| checkbox1 |x| checkbox2

|x| checkbox3 |x| checkbox4

|x| checkbox5 |x| checkbox6

|x| checkbox7 |x| checkbox8

Ex: If boxes 1, 5, and 8 were checked, then functions 1, 5, and 8 would run

Thanks,

Scott

Posted

Ex: If boxes 1, 5, and 8 were checked, then functions 1, 5, and 8 would run

Here's an example of how to do that:

#include <GUIConstants.au3>
;AutoItSetOption("guioneventmode",1)

Global $Power, $DelProfs, $IndexOff, $SyncOff, $IECache, $EmptyRecyc, $Defrag, $Reboot, $VirusScan, $GoButton

GUICreate("Clean Up Computer", 255, 350) 
GUICtrlCreateLabel("Choose your Clean Up Tasks:", 12, 18)

$Power = GUICtrlCreateCheckbox("Power Always On / Hibernate Off",20,50,190,20)
    guictrlsetstate(4,$gui_checked)
$DelProfs = GUICtrlCreateCheckbox("Delete Local Profiles",20,70,190,20)
    guictrlsetstate(5,$gui_checked)
$IndexOff = GUICtrlCreateCheckbox("Indexing Off",20,90,190,20)
    guictrlsetstate(6,$gui_checked)
$SyncOff = GUICtrlCreateCheckbox("Offline File Sync Off",20,110,190,20)
    guictrlsetstate(7,$gui_checked)
$IECache = GUICtrlCreateCheckbox("IECache 100MB / History 3 Days",20,130,190,20)
    guictrlsetstate(8,$gui_checked)
$EmptyRecyc = GUICtrlCreateCheckbox("Empty Recycle Bin",20,150,190,20)
    guictrlsetstate(9,$gui_checked)
$Defrag = GUICtrlCreateCheckbox("Defragment the C:\ Drive",20,170,190,20)
    guictrlsetstate(10,$gui_checked)
$VirusScan = GUICtrlCreateCheckbox("Scan for Viruses",20,190,190,20)
    guictrlsetstate(11,$gui_checked)
$WinACLS = GUICtrlCreateCheckbox("Run WinACLS",20,210,190,20)
    guictrlsetstate(12,$gui_checked)
$Reboot = GUICtrlCreateCheckbox("Reboot to Enable Changes",20,230,190,20)
    guictrlsetstate(13,$gui_checked)

$GoButton = GUICtrlCreateButton("GO...",20,270,100,20)
ControlFocus("Clean Up Computer", "", "Button11")
GuiSetState()
While 1             ; Wait for user to select checkboxes and then press the "Go" button to begin routines
    $msg = guigetmsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE; If user closes the dialog box the program is ended
        ExitLoop
    
    Case $msg = $GoButton       ; If user selects the Go button, all checked tasks will be run
                    
    if(GuiCtrlRead($Power)  = 1) then       
    ; Make sure power settings are correct
            RunWait(@ComSpec & ' /c ' & "regedit /s \\student2\apps$\_bin\cleanup\hibernateOFF_heuristics.reg");turn off hibernate
            RunWait(@ComSpec & ' /c ' & 'regedit /s \\student2\apps$\_bin\cleanup\PowerCFG_AlwaysOn.reg')   ;set profile to "Always On"
                SplashTextOn("Progress Report", "Power is now Always ON, Hibernate is OFF", -1, 25, -1, 200, 4, "", 12)
                Sleep(3000)
                SplashOff()
    EndIf   

    if(GuiCtrlRead($DelProfs)  = 1) then 
    ; Remove old local user profiles
            FileCopy("\\student2\apps$\_bin\cleanup\DelProfilesAnyuser.exe","c:\Documents and Settings\All Users\Desktop")
            Runwait('\\student2\apps$\_bin\cleanup\DelProfilesAnyuser.exe')                                 ;delete profiles
            ;Winwaitclose("c:\winnt\system32\cmd.exe")
            FileDelete("c:\documents and settings\all users\desktop\delProfilesAnyuser.exe")
            ;msgbox(0,"Wait for Profiles","Click OK when profile deletion is done")
                SplashTextOn("Progress Report", "User Profiles are now DELETED", -1, 25, -1, 225, 4, "", 12)
                Sleep(3000)
                SplashOff()
    EndIf

    if(GuiCtrlRead($IndexOff)  = 1) then 
    ; Turn off File Indexing
            RegWrite("HKEY_LOCAL_MACHINE\system\currentcontrolset\services\cisvc","Start","REG_DWORD","4")
                SplashTextOn("Progress Report", "File Indexing is now OFF", -1, 25, -1, 250, 4, "", 12)
                Sleep(3000)
                SplashOff() 
    EndIf

    if(GuiCtrlRead($SyncOff)  = 1) then 
    ; Turn off Offline File Synchronization             
            RegWrite("HKEY_LOCAL_MACHINE\software\microsoft\windows\currentversion\netcache","enabled","REG_DWORD","0")
                SplashTextOn("Progress Report", "Offline File Sync is now OFF", -1, 25, -1, 275, 4, "", 12)
                Sleep(3000)
                SplashOff()
    EndIf

    if(GuiCtrlRead($IECache)  = 1) then 
    ; Reduce IE cache size to 20MB History to 7 days
            RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\Cache\Content","CacheLimit","REG_DWORD","102400")
            RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\Cache\Content","PerUserItem","REG_DWORD","0")
            RegWrite("HKEY_Current_User\Software\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\Cache\Content","CachePrefix","REG_SZ","")
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Url History","DaysToKeep","REG_DWORD","3")
        ;RegWrite("HKEY_Current_User\Software\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\Cache\Content","CacheLimit","REG_DWORD","00005000")
                SplashTextOn("Progress Report", "IE Cache is now 100MB and History is 3 days", -1, 25, -1, 300, 4, "", 12)
                Sleep(3000)
                SplashOff()
    EndIf
            
    if(GuiCtrlRead($EmptyRecyc)  = 1) then 
    ; Empty recycle bin
            RunWait(@comspec & ' /c ' & '\\student2\apps$\_bin\cleanup\erb /empty')
                SplashTextOn("Progress Report", "Recycle Bin is now EMPTY", -1, 25, -1, 325, 4, "", 12)
                Sleep(3000)
                SplashOff()
    EndIf
    
    if(GuiCtrlRead($Defrag)  = 1) then 
    ; Defragment the hard disk
            Run(@comspec & ' /c ' & 'dfrg.msc c:')
            WinWaitActive("Disk Defragmenter")
            ControlClick("Disk Defragmenter","","Button2")
            WinWaitActive("Defragmentation Complete","View &Report")
            ControlClick("Defragmentation Complete", "View &Report",2)
            WinClose("Disk Defragmenter")
                SplashTextOn("Progress Report", "Harddisk is now DEFRAGMENTED", -1, 25, -1, 350, 4, "", 12)
                Sleep(3000)
                SplashOff()
    EndIf
    
    if(GuiCtrlRead($VirusScan)  = 1) then 
    ; Virusscan the hard disk
            Run('C:\Program Files\Network Associates\VirusScan\mcconsol.exe')
            WinWaitActive("VirusScan Console - ","Local System")
            Send("{DOWN}{DOWN}{DOWN}{DOWN}")
            send("!ss")
                    $text = WinGetText("VirusScan On-Demand","")
                ;msgbox(0,"Message found!",StringInStr($text,"No infected items were found"))
                    While StringInStr($text,"No infected items were found") <> 20
                        $text = WinGetText("VirusScan On-Demand","")
                    ;MsgBox(0, "Value of $text is:", $text)
                    WEnd
                            ;msgbox(0,"Message found!",StringInStr($text,"No infected items were found"))
                            ;WinClose("VirusScan On-Demand Scan Progress - New Scan");use this command for quick testing of scan of memory only
            WinClose("VirusScan On-Demand Scan Progress - Scan All Fixed Disks")
            WinClose("VirusScan Console - ","Local System") 
                SplashTextOn("Progress Report", "System is now scanned for Viruses", -1, 25, -1, 375, 4, "", 12)
                Sleep(3000)
                SplashOff()
    EndIf

    if(GuiCtrlRead($WinACLS)  = 1) then 
    ; Defragment the hard disk
            Run("\\Staff\c$\AdminDocs\Windows_2000_acl_list_v.1.5.bat")
            WinWaitActive("C:\WINNT\system32\cmd.exe")
            WinWaitClose("C:\WINNT\system32\cmd.exe")
                SplashTextOn("Progress Report", "Windows Access Control Lists now updated", -1, 25, -1, 400, 4, "", 12)
                Sleep(3000)
                SplashOff()
    EndIf

    if(GuiCtrlRead($Reboot)  = 1) then 
    ; Restart the computer to finish changing settings
            RunWait(@comspec & ' /c ' & '\\student2\apps$\_bin\shutdown.exe /L /R')
    EndIf

    MsgBox(1,"","done")

        ExitLoop
    EndSelect
WEnd
Exit
...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
Posted (edited)

I think Treeview with the $TVS_CHECKBOXES style is better if you have a lot of checkboxes.

If there are a lot of entries it will even put scrollies on the Treeview. :)

Look at this example:

; Script generated by AutoBuilder 0.5 Prototype
#include <GuiConstants.au3>

If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000

GuiCreate("TreeView", 151, 215,(@DesktopWidth-151)/2, (@DesktopHeight-215)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$TreeView = GuiCtrlCreateTreeview(10, 10, 130, 200,$TVS_CHECKBOXES)
$treeTwo = GuiCtrlCreateTreeView(295, 290, 103, 80, $TVS_CHECKBOXES)
For $X=1 to 20
GuiCtrlCreateTreeViewItem("Item" & $X, $TreeView)
Next

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
    ;;;
    EndSelect
WEnd
Exit
Edited by SolidSnake
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Posted

Check out my script:

http://www.autoitscript.com/forum/index.php?showtopic=12546

I designed it to launch external programs, but you could easily get how to use the same structure to launch internal routines.

Posted

Thanks for your help guys!

I was able to solve the problem with the information from your 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...