Sign in to follow this  
Followers 0
skippynz

how to grey out a combobox on the fly

4 posts in this topic

#1 ·  Posted (edited)

hi guys - i have a gui that has a few combo boxes etc and i want to disable one depending on what another setting is - ie if task frequency is set to once then disable the modifier for it but if someone changes it to weekly then i want to re-enable the modifier combo box - below is my gui....

TIA

Craig

AutoItSetOption('TrayIconDebug',1)

#include <INet.au3>
#Include <File.au3>
#Include <Array.au3>
#Include <Process.au3>
#include <Constants.au3>
#include <GUIListBox.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <TabConstants.au3>
#include <ComboConstants.au3>

dim $COUNT1, $DATA, $USERNAME, $PASSWORD, $SET_GUI_CHANGE_DATABASE, $SET_GUI_SQL_CODE, $SET_GUI_EXPORT_FOLDER, $SET_GUI_NO_REBOOT_DETAILS
dim $SET_GUI_NO_REBOOT_LIST, $SET_GUI_REBOOT_DETAILS, $SET_GUI_REBOOT_LIST, $SET_GUI_REBOOT_DETAILS, $SET_GUI_CREATE_LIST_FILE_YES, $SET_GUI_PASSWORD
dim $SET_GUI_CREATE_EXPORT_YES, $SET_GUI_NO_REBOOT_TASK_START_TIME, $SET_GUI_NO_REBOOT_TASK_START_DAY, $SET_GUI_NO_REBOOT_TASK_NAME
dim $SET_GUI_NO_REBOOT_TASK_FREQUENCY, $SET_GUI_NO_REBOOT_TASK_FREQUENCY_MODIFIER, $SET_GUI_NO_REBOOT_TASK_LOCATION, $SET_GUI_USERNAME
dim $SET_GUI_REBOOT_TASK_START_TIME, $SET_GUI_REBOOT_TASK_START_DAY, $SET_GUI_REBOOT_TASK_NAME, $SET_GUI_REBOOT_TASK_FREQUENCY
dim $SET_GUI_REBOOT_TASK_FREQUENCY_MODIFIER, $SET_GUI_REBOOT_TASK_LOCATION, $SET_GUI_NO_REBOOT_TASK_START_TIME
dim $SET_GUI_EMAIL, $EMAIL_DETAILS

$INIFILE = FileOpenDialog('Please choose the Patching INI file you would like to use',@scriptdir,'INI files (*.ini)',1,'standard_patching.ini')
if $INIFILE = '' Then 
    EXIT_SCRIPT()
EndIf


#Region - INI FILE READING
$DEFAULT_USERNAME = IniRead($INIFILE,'username','default_username','')

$FULL_MDB_FILE_NAME = IniRead($INIFILE,'database','location','')
$SQL_CODE = IniRead($INIFILE,'database','sqlcode','')

$NO_REBOOT_FILE = IniRead($INIFILE,'output','noreboot','')
$REBOOT_FILE = IniRead($INIFILE,'output','reboot','')
$EXPORT_FOLDER = IniRead($INIFILE,'output','export_folder','')
$CREATE_OUTPUT_FILE = IniRead($INIFILE,'output','create_output','')

$EMAIL = IniReadSection($INIFILE,'email')

$NO_REBOOT_DETAILS = IniRead($INIFILE,'details','noreboot','')
$REBOOT_DETAILS = IniRead($INIFILE,'details','reboot','')

$NO_REBOOT_TASK_NAME = IniRead($INIFILE,'noreboot_task','task_name','')
$NO_REBOOT_TASK_LOCATION = IniRead($INIFILE,'noreboot_task','task_location','')
$NO_REBOOT_TASK_START_DAY = IniRead($INIFILE,'noreboot_task','start_day','')
$NO_REBOOT_TASK_START_TIME = IniRead($INIFILE,'noreboot_task','start_time','')
$NO_REBOOT_TASK_FREQUENCY = IniRead($INIFILE,'noreboot_task','task_frequency','')
$NO_REBOOT_TASK_FREQUENCY_MODIFIER = IniRead($INIFILE,'noreboot_task','task_frequency_modifier','')

$REBOOT_TASK_NAME = IniRead($INIFILE,'reboot_task','task_name','')
$REBOOT_TASK_LOCATION = IniRead($INIFILE,'reboot_task','task_location','')
$REBOOT_TASK_START_DAY = IniRead($INIFILE,'reboot_task','start_day','')
$REBOOT_TASK_START_TIME = IniRead($INIFILE,'reboot_task','start_time','')
$REBOOT_TASK_FREQUENCY = IniRead($INIFILE,'reboot_task','task_frequency','')
$REBOOT_TASK_FREQUENCY_MODIFIER = IniRead($INIFILE,'reboot_task','task_frequency_modifier','')
#EndRegion

#Region - SETTING UP THE GUI
$GUI = GUICreate( "WSUS Patching Utility" , 535, 500, -1 , 50 , $WS_BORDER)
GUISetFont (8, 400, 0, 'verdana' )

GuiCtrlCreateLabel('WSUS Patching Utility', 190, 16, 320,20 ,$SS_RIGHT)
GUICtrlSetFont (-1, 12 , 400, -1 , "Verdana" )
GUICtrlSetColor ( -1, 0x80cccc)
GUICtrlSetBkColor ( -1, $GUI_BKCOLOR_TRANSPARENT  )

GUICtrlCreateLabel('Please fill in the details below and when ready press CREATE TASKS to setup the automatic patching.',7,60,515,30,$SS_CENTER)
GUICtrlSetColor(-1,0xff0000)

;~ username
GUICtrlCreateLabel('Username:',20,93,75)
$GUI_USERNAME = GUICtrlCreateInput($DEFAULT_USERNAME,90,90,160)

;~ password
GUICtrlCreateLabel('Password:',270,93,75)
$GUI_PASSWORD = GUICtrlCreateInput('',350,90,160,-1,bitor( $ES_LEFT, $ES_AUTOHSCROLL,$ES_PASSWORD))

;~ database
GUICtrlCreateLabel('Database:',20,120,75)
$GUI_DATABASE = GUICtrlCreateInput($FULL_MDB_FILE_NAME,90,117,330,18,$ES_READONLY)
$GUI_CHANGE_DATABASE = GUICtrlCreateButton('Change',440,114,70)

;~ sql code
GUICtrlCreateLabel('SQL Code:',20,147,75)
$GUI_SQL_CODE = GUICtrlCreateInput($SQL_CODE,90,144,418)

;~ create tabs
GUICtrlCreateTab (20, 170 , 490, 245)

;~ no reboot task details
GUICtrlCreateTabItem('Patch - No Reboot')
    GUICtrlCreateLabel('Text in the database to look for:',30,203,200)
    $GUI_NO_REBOOT_DETAILS = GUICtrlCreateInput($NO_REBOOT_DETAILS,225,200,270)
    GUICtrlCreateLabel('Task name:',30,233,200)
    $GUI_NO_REBOOT_TASK_NAME = GUICtrlCreateInput($NO_REBOOT_TASK_NAME,225,230,270)
    GUICtrlCreateLabel('Task location:',30,263,200)
    $GUI_NO_REBOOT_TASK_LOCATION = GUICtrlCreateInput($NO_REBOOT_TASK_LOCATION,225,260,270)
    GUICtrlCreateLabel('Task start day:',30,293,200)
    $GUI_NO_REBOOT_TASK_START_DAY = GUICtrlCreateCombo('',225,290,270,-1,$CBS_DROPDOWNLIST) 
        GUICtrlSetData ( -1, 'MON|TUE|WED|THU|FRI|SAT|SUN' , $NO_REBOOT_TASK_START_DAY )
    GUICtrlCreateLabel('Task start time:',30,323,200)
        GUICtrlCreateLabel('(24hr clock)',135,323)
        GUICtrlSetColor(-1,0xff0000)
    $GUI_NO_REBOOT_TASK_START_TIME = GUICtrlCreateCombo('',225,320,270)
        GUICtrlSetData ( -1, '00:00|01:00|02:00|03:00|04:00|05:00|06:00|07:00|08:00|09:00|10:00|11:00|12:00|13:00|14:00|15:00|16:00|17:00|18:00|19:00|20:00|21:00|22:00|23:00' , $NO_REBOOT_TASK_START_TIME )
    GUICtrlCreateLabel('Task frequency:',30,353,200)
    $GUI_NO_REBOOT_TASK_FREQUENCY = GUICtrlCreateCombo('',225,350,270,-1,$CBS_DROPDOWNLIST) 
        GUICtrlSetData ( -1, 'ONCE|WEEKLY' , $NO_REBOOT_TASK_FREQUENCY)
    GUICtrlCreateLabel('Task frequency modifier:',30,383,200)
    $GUI_NO_REBOOT_TASK_FREQUENCY_MODIFIER = GUICtrlCreateCombo('',225,380,270,-1,$CBS_DROPDOWNLIST) 
        GUICtrlSetData ( -1, '1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|




36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52' , $NO_REBOOT_TASK_FREQUENCY_MODIFIER )

;~ reboot task details
GUICtrlCreateTabItem('Patch - Reboot')
    GUICtrlCreateLabel('Text in the database to look for:',30,203,200)
    $GUI_REBOOT_DETAILS = GUICtrlCreateInput($REBOOT_DETAILS,225,200,270)
    GUICtrlCreateLabel('Task name:',30,233,200)
    $GUI_REBOOT_TASK_NAME = GUICtrlCreateInput($REBOOT_TASK_NAME,225,230,270)
    GUICtrlCreateLabel('Task location:',30,263,200)
    $GUI_REBOOT_TASK_LOCATION = GUICtrlCreateInput($REBOOT_TASK_LOCATION,225,260,270)
    GUICtrlCreateLabel('Task start day:',30,293,200)
    $GUI_REBOOT_TASK_START_DAY = GUICtrlCreateCombo('',225,290,270,-1,$CBS_DROPDOWNLIST) 
        GUICtrlSetData ( -1, 'MON|TUE|WED|THU|FRI|SAT|SUN' , $REBOOT_TASK_START_DAY )
    GUICtrlCreateLabel('Task start time:',30,323,200)
        GUICtrlCreateLabel('(24hr clock)',135,323)
        GUICtrlSetColor(-1,0xff0000)
    $GUI_REBOOT_TASK_START_TIME = GUICtrlCreateCombo('',225,320,270) 
        GUICtrlSetData ( -1, '00:00|01:00|02:00|03:00|04:00|05:00|06:00|07:00|08:00|09:00|10:00|11:00|12:00|13:00|14:00|15:00|16:00|17:00|18:00|19:00|20:00|21:00|22:00|23:00' , $REBOOT_TASK_START_TIME )
    GUICtrlCreateLabel('Task frequency:',30,353,200)
    $GUI_REBOOT_TASK_FREQUENCY = GUICtrlCreateCombo('',225,350,270,-1,$CBS_DROPDOWNLIST) 
        GUICtrlSetData ( -1, 'ONCE|WEEKLY' , $REBOOT_TASK_FREQUENCY )
    GUICtrlCreateLabel('Task frequency modifier:',30,383,200)
    $GUI_REBOOT_TASK_FREQUENCY_MODIFIER = GUICtrlCreateCombo('',225,380,270,-1,$CBS_DROPDOWNLIST) 
        GUICtrlSetData ( -1, '1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|




36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52' , $REBOOT_TASK_FREQUENCY_MODIFIER )

;~ output and log settings
GUICtrlCreateTabItem('Output and Log Settings')
    GUICtrlCreateLabel('Debugging export folder:',30,203,200)
    $GUI_EXPORT_FOLDER = GUICtrlCreateInput($EXPORT_FOLDER,225,200,270)

    GUIStartGroup() 
    GUICtrlCreateLabel('Do you want to list the servers from the database:',30,230,190,30)
    $GUI_CREATE_LIST_FILE_YES = GUICtrlCreateRadio('Yes',225,230,50)
    $GUI_CREATE_LIST_FILE_NO = GUICtrlCreateRadio('No',295,230,50)
    if $CREATE_OUTPUT_FILE = 'yes' Then
        GUICtrlSetState($GUI_CREATE_LIST_FILE_YES, $GUI_CHECKED)
    EndIf
    GUICtrlCreateLabel('No reboot server list:',30,263,200)
    $GUI_NO_REBOOT_LIST = GUICtrlCreateInput($NO_REBOOT_FILE,225,260,270)
    GUICtrlCreateLabel('Reboot server list:',30,293,200)
    $GUI_REBOOT_LIST = GUICtrlCreateInput($REBOOT_FILE,225,290,270)
    
    GUIStartGroup() 
    GUICtrlCreateLabel('Do you want to export the scheduled tasks on each server:',30,320,190,30)
    $GUI_CREATE_EXPORT_YES = GUICtrlCreateRadio('Yes',225,320,50)
    $GUI_CREATE_EXPORT_NO = GUICtrlCreateRadio('No',295,320,50)
    if $CREATE_OUTPUT_FILE = 'yes' Then
        GUICtrlSetState($GUI_CREATE_EXPORT_YES, $GUI_CHECKED)
    EndIf

;~ settings
GUICtrlCreateTabItem('Email Settings')
    GUICtrlCreateLabel('Please select the people that will receive the WSUS Emails:',30,203,250,35)
    GUICtrlCreateLabel('Hold CTRL to select multiple people',30,230,250)
    GUICtrlSetColor(-1,0xff0000)
    $GUI_EMAIL = GUICtrlCreateList('', 300,200,195,80,BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL))
    For $x = 1 to $EMAIL[0][0]
        GUICtrlSetData(-1,$EMAIL[$x][1])
    Next
    
GUICtrlCreateTabItem('')

$GUI_EXIT = GUICtrlCreateButton('Exit',20,430,240,35)
$GUI_CREATE_TASKS = GUICtrlCreateButton('Create Tasks',270,430,240,35)
#EndRegion

#Region - DISPLAY THE GUI
GUISetState(@SW_SHOW,$GUI); will display an empty dialog box
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        SET_OPTIONS()
        EXIT_SCRIPT()
    EndIf
    If $msg = $GUI_EXIT Then 
        SET_OPTIONS()
        EXIT_SCRIPT()
    EndIf
    if $msg = $GUI_CHANGE_DATABASE Then
        $NEW_DATABASE = FileOpenDialog('Please select the database you would like to use.',@ScriptDir,'MDB Files (*.mdb)',1)
        GUICtrlSetData($GUI_DATABASE,$NEW_DATABASE)
    EndIf
    If $msg = $GUI_CREATE_TASKS Then 
        SET_OPTIONS()
        $SET_GUI_EMAIL_1 = _ArrayToString($SET_GUI_EMAIL,';',1)
        if $SET_GUI_PASSWORD = '' Then
            msgbox(0,'Password','You must enter a password to setup the scheduled tasks - please do this now and try again.')
        ElseIf $SET_GUI_EMAIL_1 = '' Then
            msgbox(0,'Email','You must select an email address for the debugging and completion emails - please do this now and try again.')
        Else
            GUISetState(@SW_HIDE,$GUI)
            DELETE_FILES()
            READ_DATABASE()
            EXIT_SCRIPT()
        EndIf
    EndIf
WEnd
#EndRegion

#Region - EXIT SCRIPT
Func EXIT_SCRIPT()
    FileDelete('logo.gif')
    Exit
EndFunc
#EndRegion

#Region - SET OPTIONS
Func SET_OPTIONS()
    $SET_GUI_USERNAME = GUICtrlRead($GUI_USERNAME)
    $SET_GUI_PASSWORD = GUICtrlRead($GUI_PASSWORD)
    $SET_GUI_CHANGE_DATABASE = GUICtrlRead($GUI_DATABASE)
    $SET_GUI_SQL_CODE = GUICtrlRead($GUI_SQL_CODE)
    $SET_GUI_NO_REBOOT_DETAILS = GUICtrlRead($GUI_NO_REBOOT_DETAILS)
    $SET_GUI_NO_REBOOT_TASK_NAME = GUICtrlRead($GUI_NO_REBOOT_TASK_NAME)
    $SET_GUI_NO_REBOOT_TASK_LOCATION = GUICtrlRead($GUI_NO_REBOOT_TASK_LOCATION)
    $SET_GUI_NO_REBOOT_TASK_START_DAY = GUICtrlRead($GUI_NO_REBOOT_TASK_START_DAY)
    $SET_GUI_NO_REBOOT_TASK_START_TIME = GUICtrlRead($GUI_NO_REBOOT_TASK_START_TIME)
    $SET_GUI_NO_REBOOT_TASK_FREQUENCY = GUICtrlRead($GUI_NO_REBOOT_TASK_FREQUENCY)
    $SET_GUI_NO_REBOOT_TASK_FREQUENCY_MODIFIER = GUICtrlRead($GUI_NO_REBOOT_TASK_FREQUENCY_MODIFIER)
    $SET_GUI_REBOOT_DETAILS = GUICtrlRead($GUI_REBOOT_DETAILS)
    $SET_GUI_REBOOT_TASK_NAME = GUICtrlRead($GUI_REBOOT_TASK_NAME)
    $SET_GUI_REBOOT_TASK_LOCATION = GUICtrlRead($GUI_REBOOT_TASK_LOCATION)
    $SET_GUI_REBOOT_TASK_START_DAY = GUICtrlRead($GUI_REBOOT_TASK_START_DAY)
    $SET_GUI_REBOOT_TASK_START_TIME = GUICtrlRead($GUI_REBOOT_TASK_START_TIME)
    $SET_GUI_REBOOT_TASK_FREQUENCY = GUICtrlRead($GUI_REBOOT_TASK_FREQUENCY)
    $SET_GUI_REBOOT_TASK_FREQUENCY_MODIFIER = GUICtrlRead($GUI_REBOOT_TASK_FREQUENCY_MODIFIER)
    $SET_GUI_CREATE_LIST_FILE_YES = GUICtrlRead($GUI_CREATE_LIST_FILE_YES)
    $SET_GUI_CREATE_LIST_FILE_NO = GUICtrlRead($GUI_CREATE_LIST_FILE_NO)
    $SET_GUI_NO_REBOOT_LIST = GUICtrlRead($GUI_NO_REBOOT_LIST)
    $SET_GUI_REBOOT_LIST = GUICtrlRead($GUI_REBOOT_LIST)
    $SET_GUI_CREATE_EXPORT_YES = GUICtrlRead($GUI_CREATE_EXPORT_YES)
    $SET_GUI_CREATE_EXPORT_NO = GUICtrlRead($GUI_CREATE_EXPORT_NO)
    $SET_GUI_EXPORT_FOLDER = GUICtrlRead($GUI_EXPORT_FOLDER)
    $SET_GUI_EXIT = GUICtrlRead($GUI_EXIT)
    $SET_GUI_CREATE_TASKS = GUICtrlRead($GUI_CREATE_TASKS)
    $SET_GUI_EMAIL = _GUICtrlListBox_GetSelItemsText($GUI_EMAIL)
EndFunc
#EndRegion

#Region - DATABASE READING
Func READ_DATABASE()
    $CONN = ObjCreate('ADODB.Connection')
    $CONN.Open('Driver={Microsoft Access Driver (*.mdb)};Dbq=' & $SET_GUI_CHANGE_DATABASE & ';')
    $RecordSet = ObjCreate('ADODB.Recordset')
    $RecordSet.Open($SET_GUI_SQL_CODE, $CONN)
    $DATA = $RecordSet.GetRows()
    $RecordSet.Close
    $CONN.Close

    $CONN1 = ObjCreate('ADODB.Connection')
    $CONN1.Open('Driver={Microsoft Access Driver (*.mdb)};Dbq=' & $SET_GUI_CHANGE_DATABASE & ';')
    $count = ObjCreate('ADODB.Recordset')
    $count.Open('SELECT count(*) from ServerInfo', $CONN1)
    $COUNT1 = $count.GetRows()
    $count.Close
        
EndFunc
#EndRegion

#Region - DELETE FILES
Func DELETE_FILES()
    if FileExists($SET_GUI_EXPORT_FOLDER) then DirRemove($SET_GUI_EXPORT_FOLDER,1)
    sleep(1000)
    DirCreate($SET_GUI_EXPORT_FOLDER)
EndFunc
#EndRegion

heres my ini file im reading in

[username]
default_username=bob\bobadmin

[database]
location=Invent.mdb
sqlcode=SELECT Server,Shutdown from ServerInfo

[output]
noreboot=Patch_NO_Reboot.txt
reboot=Patch_AND_Reboot.txt
export_folder=.\debug
create_output=yes

[details]
noreboot=Patch - NO Reboot
reboot=Patch - Reboot

[noreboot_task]
task_name=Server - Patch and No Reboot
task_location=command to run here
start_day=FRI
start_time=10:00
task_frequency=ONCE
task_frequency_modifier=50

[reboot_task]
task_name=Server - Patch and Reboot
task_location=command to run here
start_day=FRI
start_time=10:00
task_frequency=ONCE
task_frequency_modifier=50

[email]
email_1=bob1@bob.com
email_2=bob2@bob.com
Edited by craig.gill

Share this post


Link to post
Share on other sites



i put this in the while section - which does what i want it too do but it flashes everytime i move the mouse - is there a way to stop that from happening ?

if GUICtrlRead($GUI_NO_REBOOT_TASK_FREQUENCY) = 'ONCE' Then
        GUICtrlSetState($GUI_NO_REBOOT_TASK_FREQUENCY_MODIFIER,$GUI_DISABLE)
    Else 
        GUICtrlSetState($GUI_NO_REBOOT_TASK_FREQUENCY_MODIFIER,$GUI_ENABLE)
    EndIf

Share this post


Link to post
Share on other sites

craig.gill,

This is a very common problem. At present you are polling the combo on every pass throught the While...WEnd loop - and activating the GUICtrlSetState each time. That is what is giving the flicker.

The solution is to set a flag variable to indicate the current state of the combo which acts as the switch. Then you test both the combo content and the flag and only change the state of the second combo if they do NOT match. You also need to enable/disable the second combo when it is created so that it matches the required flag state.

I have added a few lines to your script - they are marked by "; <<<<<<<<<<<<<<<":

AutoItSetOption('TrayIconDebug',1)

#include <INet.au3>
#Include <File.au3>
#Include <Array.au3>
#Include <Process.au3>
#include <Constants.au3>
#include <GUIListBox.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <TabConstants.au3>
#include <ComboConstants.au3>

dim $COUNT1, $DATA, $USERNAME, $PASSWORD, $SET_GUI_CHANGE_DATABASE, $SET_GUI_SQL_CODE, $SET_GUI_EXPORT_FOLDER, $SET_GUI_NO_REBOOT_DETAILS
dim $SET_GUI_NO_REBOOT_LIST, $SET_GUI_REBOOT_DETAILS, $SET_GUI_REBOOT_LIST, $SET_GUI_REBOOT_DETAILS, $SET_GUI_CREATE_LIST_FILE_YES, $SET_GUI_PASSWORD
dim $SET_GUI_CREATE_EXPORT_YES, $SET_GUI_NO_REBOOT_TASK_START_TIME, $SET_GUI_NO_REBOOT_TASK_START_DAY, $SET_GUI_NO_REBOOT_TASK_NAME
dim $SET_GUI_NO_REBOOT_TASK_FREQUENCY, $SET_GUI_NO_REBOOT_TASK_FREQUENCY_MODIFIER, $SET_GUI_NO_REBOOT_TASK_LOCATION, $SET_GUI_USERNAME
dim $SET_GUI_REBOOT_TASK_START_TIME, $SET_GUI_REBOOT_TASK_START_DAY, $SET_GUI_REBOOT_TASK_NAME, $SET_GUI_REBOOT_TASK_FREQUENCY
dim $SET_GUI_REBOOT_TASK_FREQUENCY_MODIFIER, $SET_GUI_REBOOT_TASK_LOCATION, $SET_GUI_NO_REBOOT_TASK_START_TIME
dim $SET_GUI_EMAIL, $EMAIL_DETAILS

$INIFILE = FileOpenDialog('Please choose the Patching INI file you would like to use',@scriptdir,'INI files (*.ini)',1,'standard_patching.ini')
if $INIFILE = '' Then 
    EXIT_SCRIPT()
EndIf


#Region - INI FILE READING
$DEFAULT_USERNAME = IniRead($INIFILE,'username','default_username','')

$FULL_MDB_FILE_NAME = IniRead($INIFILE,'database','location','')
$SQL_CODE = IniRead($INIFILE,'database','sqlcode','')

$NO_REBOOT_FILE = IniRead($INIFILE,'output','noreboot','')
$REBOOT_FILE = IniRead($INIFILE,'output','reboot','')
$EXPORT_FOLDER = IniRead($INIFILE,'output','export_folder','')
$CREATE_OUTPUT_FILE = IniRead($INIFILE,'output','create_output','')

$EMAIL = IniReadSection($INIFILE,'email')

$NO_REBOOT_DETAILS = IniRead($INIFILE,'details','noreboot','')
$REBOOT_DETAILS = IniRead($INIFILE,'details','reboot','')

$NO_REBOOT_TASK_NAME = IniRead($INIFILE,'noreboot_task','task_name','')
$NO_REBOOT_TASK_LOCATION = IniRead($INIFILE,'noreboot_task','task_location','')
$NO_REBOOT_TASK_START_DAY = IniRead($INIFILE,'noreboot_task','start_day','')
$NO_REBOOT_TASK_START_TIME = IniRead($INIFILE,'noreboot_task','start_time','')
$NO_REBOOT_TASK_FREQUENCY = IniRead($INIFILE,'noreboot_task','task_frequency','')
$NO_REBOOT_TASK_FREQUENCY_MODIFIER = IniRead($INIFILE,'noreboot_task','task_frequency_modifier','')

$REBOOT_TASK_NAME = IniRead($INIFILE,'reboot_task','task_name','')
$REBOOT_TASK_LOCATION = IniRead($INIFILE,'reboot_task','task_location','')
$REBOOT_TASK_START_DAY = IniRead($INIFILE,'reboot_task','start_day','')
$REBOOT_TASK_START_TIME = IniRead($INIFILE,'reboot_task','start_time','')
$REBOOT_TASK_FREQUENCY = IniRead($INIFILE,'reboot_task','task_frequency','')
$REBOOT_TASK_FREQUENCY_MODIFIER = IniRead($INIFILE,'reboot_task','task_frequency_modifier','')
#EndRegion

#Region - SETTING UP THE GUI
$GUI = GUICreate( "WSUS Patching Utility" , 535, 500, -1 , 50 , $WS_BORDER)
GUISetFont (8, 400, 0, 'verdana' )

GuiCtrlCreateLabel('WSUS Patching Utility', 190, 16, 320,20 ,$SS_RIGHT)
GUICtrlSetFont (-1, 12 , 400, -1 , "Verdana" )
GUICtrlSetColor ( -1, 0x80cccc)
GUICtrlSetBkColor ( -1, $GUI_BKCOLOR_TRANSPARENT  )

GUICtrlCreateLabel('Please fill in the details below and when ready press CREATE TASKS to setup the automatic patching.',7,60,515,30,$SS_CENTER)
GUICtrlSetColor(-1,0xff0000)

;~ username
GUICtrlCreateLabel('Username:',20,93,75)
$GUI_USERNAME = GUICtrlCreateInput($DEFAULT_USERNAME,90,90,160)

;~ password
GUICtrlCreateLabel('Password:',270,93,75)
$GUI_PASSWORD = GUICtrlCreateInput('',350,90,160,-1,bitor( $ES_LEFT, $ES_AUTOHSCROLL,$ES_PASSWORD))

;~ database
GUICtrlCreateLabel('Database:',20,120,75)
$GUI_DATABASE = GUICtrlCreateInput($FULL_MDB_FILE_NAME,90,117,330,18,$ES_READONLY)
$GUI_CHANGE_DATABASE = GUICtrlCreateButton('Change',440,114,70)

;~ sql code
GUICtrlCreateLabel('SQL Code:',20,147,75)
$GUI_SQL_CODE = GUICtrlCreateInput($SQL_CODE,90,144,418)

;~ create tabs
GUICtrlCreateTab (20, 170 , 490, 245)

;~ no reboot task details
GUICtrlCreateTabItem('Patch - No Reboot')
    GUICtrlCreateLabel('Text in the database to look for:',30,203,200)
    $GUI_NO_REBOOT_DETAILS = GUICtrlCreateInput($NO_REBOOT_DETAILS,225,200,270)
    GUICtrlCreateLabel('Task name:',30,233,200)
    $GUI_NO_REBOOT_TASK_NAME = GUICtrlCreateInput($NO_REBOOT_TASK_NAME,225,230,270)
    GUICtrlCreateLabel('Task location:',30,263,200)
    $GUI_NO_REBOOT_TASK_LOCATION = GUICtrlCreateInput($NO_REBOOT_TASK_LOCATION,225,260,270)
    GUICtrlCreateLabel('Task start day:',30,293,200)
    $GUI_NO_REBOOT_TASK_START_DAY = GUICtrlCreateCombo('',225,290,270,-1,$CBS_DROPDOWNLIST) 
        GUICtrlSetData ( -1, 'MON|TUE|WED|THU|FRI|SAT|SUN' , $NO_REBOOT_TASK_START_DAY )
    GUICtrlCreateLabel('Task start time:',30,323,200)
        GUICtrlCreateLabel('(24hr clock)',135,323)
        GUICtrlSetColor(-1,0xff0000)
    $GUI_NO_REBOOT_TASK_START_TIME = GUICtrlCreateCombo('',225,320,270)
        GUICtrlSetData ( -1, '00:00|01:00|02:00|03:00|04:00|05:00|06:00|07:00|08:00|09:00|10:00|11:00|12:00|13:00|14:00|' & _
        '15:00|16:00|17:00|18:00|19:00|20:00|21:00|22:00|23:00' , $NO_REBOOT_TASK_START_TIME )
    GUICtrlCreateLabel('Task frequency:',30,353,200)
    $GUI_NO_REBOOT_TASK_FREQUENCY = GUICtrlCreateCombo('',225,350,270,-1,$CBS_DROPDOWNLIST) 
        GUICtrlSetData ( -1, 'ONCE|WEEKLY' , $NO_REBOOT_TASK_FREQUENCY)
        $GUI_NO_REBOOT_TASK_STATE = $NO_REBOOT_TASK_FREQUENCY   ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    GUICtrlCreateLabel('Task frequency modifier:',30,383,200)
    $GUI_NO_REBOOT_TASK_FREQUENCY_MODIFIER = GUICtrlCreateCombo('',225,380,270,-1,$CBS_DROPDOWNLIST) 
        GUICtrlSetData ( -1, '1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|' & _
        '33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52' , $NO_REBOOT_TASK_FREQUENCY_MODIFIER )
        If $NO_REBOOT_TASK_FREQUENCY = "ONCE" Then GUICtrlSetState(-1 , $GUI_DISABLE) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    GUICtrlCreateLabel('Task frequency modifier:',30,383,200)

;~ reboot task details
GUICtrlCreateTabItem('Patch - Reboot')
    GUICtrlCreateLabel('Text in the database to look for:',30,203,200)
    $GUI_REBOOT_DETAILS = GUICtrlCreateInput($REBOOT_DETAILS,225,200,270)
    GUICtrlCreateLabel('Task name:',30,233,200)
    $GUI_REBOOT_TASK_NAME = GUICtrlCreateInput($REBOOT_TASK_NAME,225,230,270)
    GUICtrlCreateLabel('Task location:',30,263,200)
    $GUI_REBOOT_TASK_LOCATION = GUICtrlCreateInput($REBOOT_TASK_LOCATION,225,260,270)
    GUICtrlCreateLabel('Task start day:',30,293,200)
    $GUI_REBOOT_TASK_START_DAY = GUICtrlCreateCombo('',225,290,270,-1,$CBS_DROPDOWNLIST) 
        GUICtrlSetData ( -1, 'MON|TUE|WED|THU|FRI|SAT|SUN' , $REBOOT_TASK_START_DAY )
    GUICtrlCreateLabel('Task start time:',30,323,200)
        GUICtrlCreateLabel('(24hr clock)',135,323)
        GUICtrlSetColor(-1,0xff0000)
    $GUI_REBOOT_TASK_START_TIME = GUICtrlCreateCombo('',225,320,270) 
        GUICtrlSetData ( -1, '00:00|01:00|02:00|03:00|04:00|05:00|06:00|07:00|08:00|09:00|10:00|11:00|12:00|13:00|14:00|' & _
        '15:00|16:00|17:00|18:00|19:00|20:00|21:00|22:00|23:00' , $REBOOT_TASK_START_TIME )
    GUICtrlCreateLabel('Task frequency:',30,353,200)
    $GUI_REBOOT_TASK_FREQUENCY = GUICtrlCreateCombo('',225,350,270,-1,$CBS_DROPDOWNLIST) 
        GUICtrlSetData ( -1, 'ONCE|WEEKLY' , $REBOOT_TASK_FREQUENCY )
    GUICtrlCreateLabel('Task frequency modifier:',30,383,200)
    $GUI_REBOOT_TASK_FREQUENCY_MODIFIER = GUICtrlCreateCombo('',225,380,270,-1,$CBS_DROPDOWNLIST) 
        GUICtrlSetData ( -1, '1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|' & _ 
        '33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52' , $REBOOT_TASK_FREQUENCY_MODIFIER )

;~ output and log settings
GUICtrlCreateTabItem('Output and Log Settings')
    GUICtrlCreateLabel('Debugging export folder:',30,203,200)
    $GUI_EXPORT_FOLDER = GUICtrlCreateInput($EXPORT_FOLDER,225,200,270)

    GUIStartGroup() 
    GUICtrlCreateLabel('Do you want to list the servers from the database:',30,230,190,30)
    $GUI_CREATE_LIST_FILE_YES = GUICtrlCreateRadio('Yes',225,230,50)
    $GUI_CREATE_LIST_FILE_NO = GUICtrlCreateRadio('No',295,230,50)
    if $CREATE_OUTPUT_FILE = 'yes' Then
        GUICtrlSetState($GUI_CREATE_LIST_FILE_YES, $GUI_CHECKED)
    EndIf
    GUICtrlCreateLabel('No reboot server list:',30,263,200)
    $GUI_NO_REBOOT_LIST = GUICtrlCreateInput($NO_REBOOT_FILE,225,260,270)
    GUICtrlCreateLabel('Reboot server list:',30,293,200)
    $GUI_REBOOT_LIST = GUICtrlCreateInput($REBOOT_FILE,225,290,270)
    
    GUIStartGroup() 
    GUICtrlCreateLabel('Do you want to export the scheduled tasks on each server:',30,320,190,30)
    $GUI_CREATE_EXPORT_YES = GUICtrlCreateRadio('Yes',225,320,50)
    $GUI_CREATE_EXPORT_NO = GUICtrlCreateRadio('No',295,320,50)
    if $CREATE_OUTPUT_FILE = 'yes' Then
        GUICtrlSetState($GUI_CREATE_EXPORT_YES, $GUI_CHECKED)
    EndIf

;~ settings
GUICtrlCreateTabItem('Email Settings')
    GUICtrlCreateLabel('Please select the people that will receive the WSUS Emails:',30,203,250,35)
    GUICtrlCreateLabel('Hold CTRL to select multiple people',30,230,250)
    GUICtrlSetColor(-1,0xff0000)
    $GUI_EMAIL = GUICtrlCreateList('', 300,200,195,80,BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL))
    For $x = 1 to $EMAIL[0][0]
        GUICtrlSetData(-1,$EMAIL[$x][1])
    Next
    
GUICtrlCreateTabItem('')

$GUI_EXIT = GUICtrlCreateButton('Exit',20,430,240,35)
$GUI_CREATE_TASKS = GUICtrlCreateButton('Create Tasks',270,430,240,35)
#EndRegion

#Region - DISPLAY THE GUI
GUISetState(@SW_SHOW,$GUI); will display an empty dialog box
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        SET_OPTIONS()
        EXIT_SCRIPT()
    EndIf
    If $msg = $GUI_EXIT Then 
        SET_OPTIONS()
        EXIT_SCRIPT()
    EndIf
    if $msg = $GUI_CHANGE_DATABASE Then
        $NEW_DATABASE = FileOpenDialog('Please select the database you would like to use.',@ScriptDir,'MDB Files (*.mdb)',1)
        GUICtrlSetData($GUI_DATABASE,$NEW_DATABASE)
    EndIf
    If $msg = $GUI_CREATE_TASKS Then 
        SET_OPTIONS()
        $SET_GUI_EMAIL_1 = _ArrayToString($SET_GUI_EMAIL,';',1)
        if $SET_GUI_PASSWORD = '' Then
            msgbox(0,'Password','You must enter a password to setup the scheduled tasks - please do this now and try again.')
        ElseIf $SET_GUI_EMAIL_1 = '' Then
            msgbox(0,'Email','You must select an email address for the debugging and completion emails - please do this now and try again.')
        Else
            GUISetState(@SW_HIDE,$GUI)
            DELETE_FILES()
            READ_DATABASE()
            EXIT_SCRIPT()
        EndIf
    EndIf
    
    if GUICtrlRead($GUI_NO_REBOOT_TASK_FREQUENCY) = 'ONCE' And $GUI_NO_REBOOT_TASK_STATE <> "ONCE" Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
        GUICtrlSetState($GUI_NO_REBOOT_TASK_FREQUENCY_MODIFIER,$GUI_DISABLE)
        $GUI_NO_REBOOT_TASK_STATE = "ONCE"  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    ElseIf GUICtrlRead($GUI_NO_REBOOT_TASK_FREQUENCY) = 'WEEKLY' And $GUI_NO_REBOOT_TASK_STATE <> "WEEKLY" Then
        GUICtrlSetState($GUI_NO_REBOOT_TASK_FREQUENCY_MODIFIER,$GUI_ENABLE)
        $GUI_NO_REBOOT_TASK_STATE = "WEEKLY"; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    EndIf
    
WEnd
#EndRegion

#Region - EXIT SCRIPT
Func EXIT_SCRIPT()
    FileDelete('logo.gif')
    Exit
EndFunc
#EndRegion

#Region - SET OPTIONS
Func SET_OPTIONS()
    $SET_GUI_USERNAME = GUICtrlRead($GUI_USERNAME)
    $SET_GUI_PASSWORD = GUICtrlRead($GUI_PASSWORD)
    $SET_GUI_CHANGE_DATABASE = GUICtrlRead($GUI_DATABASE)
    $SET_GUI_SQL_CODE = GUICtrlRead($GUI_SQL_CODE)
    $SET_GUI_NO_REBOOT_DETAILS = GUICtrlRead($GUI_NO_REBOOT_DETAILS)
    $SET_GUI_NO_REBOOT_TASK_NAME = GUICtrlRead($GUI_NO_REBOOT_TASK_NAME)
    $SET_GUI_NO_REBOOT_TASK_LOCATION = GUICtrlRead($GUI_NO_REBOOT_TASK_LOCATION)
    $SET_GUI_NO_REBOOT_TASK_START_DAY = GUICtrlRead($GUI_NO_REBOOT_TASK_START_DAY)
    $SET_GUI_NO_REBOOT_TASK_START_TIME = GUICtrlRead($GUI_NO_REBOOT_TASK_START_TIME)
    $SET_GUI_NO_REBOOT_TASK_FREQUENCY = GUICtrlRead($GUI_NO_REBOOT_TASK_FREQUENCY)
    $SET_GUI_NO_REBOOT_TASK_FREQUENCY_MODIFIER = GUICtrlRead($GUI_NO_REBOOT_TASK_FREQUENCY_MODIFIER)
    $SET_GUI_REBOOT_DETAILS = GUICtrlRead($GUI_REBOOT_DETAILS)
    $SET_GUI_REBOOT_TASK_NAME = GUICtrlRead($GUI_REBOOT_TASK_NAME)
    $SET_GUI_REBOOT_TASK_LOCATION = GUICtrlRead($GUI_REBOOT_TASK_LOCATION)
    $SET_GUI_REBOOT_TASK_START_DAY = GUICtrlRead($GUI_REBOOT_TASK_START_DAY)
    $SET_GUI_REBOOT_TASK_START_TIME = GUICtrlRead($GUI_REBOOT_TASK_START_TIME)
    $SET_GUI_REBOOT_TASK_FREQUENCY = GUICtrlRead($GUI_REBOOT_TASK_FREQUENCY)
    $SET_GUI_REBOOT_TASK_FREQUENCY_MODIFIER = GUICtrlRead($GUI_REBOOT_TASK_FREQUENCY_MODIFIER)
    $SET_GUI_CREATE_LIST_FILE_YES = GUICtrlRead($GUI_CREATE_LIST_FILE_YES)
    $SET_GUI_CREATE_LIST_FILE_NO = GUICtrlRead($GUI_CREATE_LIST_FILE_NO)
    $SET_GUI_NO_REBOOT_LIST = GUICtrlRead($GUI_NO_REBOOT_LIST)
    $SET_GUI_REBOOT_LIST = GUICtrlRead($GUI_REBOOT_LIST)
    $SET_GUI_CREATE_EXPORT_YES = GUICtrlRead($GUI_CREATE_EXPORT_YES)
    $SET_GUI_CREATE_EXPORT_NO = GUICtrlRead($GUI_CREATE_EXPORT_NO)
    $SET_GUI_EXPORT_FOLDER = GUICtrlRead($GUI_EXPORT_FOLDER)
    $SET_GUI_EXIT = GUICtrlRead($GUI_EXIT)
    $SET_GUI_CREATE_TASKS = GUICtrlRead($GUI_CREATE_TASKS)
    $SET_GUI_EMAIL = _GUICtrlListBox_GetSelItemsText($GUI_EMAIL)
EndFunc
#EndRegion

#Region - DATABASE READING
Func READ_DATABASE()
    $CONN = ObjCreate('ADODB.Connection')
    $CONN.Open('Driver={Microsoft Access Driver (*.mdb)};Dbq=' & $SET_GUI_CHANGE_DATABASE & ';')
    $RecordSet = ObjCreate('ADODB.Recordset')
    $RecordSet.Open($SET_GUI_SQL_CODE, $CONN)
    $DATA = $RecordSet.GetRows()
    $RecordSet.Close
    $CONN.Close

    $CONN1 = ObjCreate('ADODB.Connection')
    $CONN1.Open('Driver={Microsoft Access Driver (*.mdb)};Dbq=' & $SET_GUI_CHANGE_DATABASE & ';')
    $count = ObjCreate('ADODB.Recordset')
    $count.Open('SELECT count(*) from ServerInfo', $CONN1)
    $COUNT1 = $count.GetRows()
    $count.Close
        
EndFunc
#EndRegion

#Region - DELETE FILES
Func DELETE_FILES()
    if FileExists($SET_GUI_EXPORT_FOLDER) then DirRemove($SET_GUI_EXPORT_FOLDER,1)
    sleep(1000)
    DirCreate($SET_GUI_EXPORT_FOLDER)
EndFunc
#EndRegion

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

thanks for your help - i'll have to make note of that for the next time i do this sort of gui... :P

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0