Sign in to follow this  
Followers 0
mdwerne

Creating a ComboBox with values for schtasks /ST

5 posts in this topic

#1 ·  Posted (edited)

So I apologize in advance for the horrible mess you see below. While there may be many issues with my code, I only need help with one part. This GUI is an interface for customers to install software pushed via SCCM. While I have Continue and Abort buttons working just fine, I'm trying to implement a scheduler that will allow the customer to defer the install for later in the day up until 11:30pm.

I'd like to have the combobox display the current time (12 hour format) and then all hours (both top and bottom of the hour) until 11:30pm. So if they check the "Defer" box, select a time from the dropdown (such as 8:30pm) and click "Go"...the time chosen will be sent to my 'unfinished' Scheduler function which will then create a task to be executed at the specified time. I hope that all makes some sense.

So again, the only thing I would like some help with is how to correctly create the combobox with the possible values based on the current local time. I should be able to figure out the rest.

Thanks for any suggestions,

-Mike

Edit:...Oops, if the moderator would like to move this post to the "Graphical User Interface (GUI) Help and Support", I wasn't thinking when I hit submit...sorry.

#include "_XMLDomWrapper.au3"
#include <Constants.au3>
#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Date.au3>

;Global $sFile = (@ScriptDir & "\Config.xml")
Global $hGUI, $FormTitle, $RTFName, $ProgramName, $TrayTip, $ShutdownTimer, $ParamName, $AbortAllowed, $AbortButtonName, $ContinueButtonName, $GoButton, $Scheduler
Global $hRichEdit, $ExitCode, $Width, $Height, $sHours

If @DesktopWidth > 1024 Then
    $Width = 1024
Else
    $Width = @DesktopWidth
EndIf

If @DesktopHeight > 768 Then
    $Height = 768
Else
    $Height = @DesktopHeight
EndIf

;_XMLFileOpen($sFile)

$FormTitle = _XMLGetAttrib("/MessageInfo/Title", "FormTitle")
$RTFName = _XMLGetAttrib("/MessageInfo/Display", "RTFName")
$ProgramName = _XMLGetAttrib("/MessageInfo/Program", "ProgramName")
$TrayTip = _XMLGetAttrib("/MessageInfo/TrayTip", "TrayTip")
$ShutdownTimer = _XMLGetAttrib("/MessageInfo/ShutdownTimer", "ShutdownTimer")
$ParamName = _XMLGetAttrib("/MessageInfo/Param", "ParamName")
$AbortAllowed = _XMLGetAttrib("/MessageInfo/Abort", "AbortAllowed")
$AbortButtonName = _XMLGetAttrib("/MessageInfo/ABN", "AbortButtonName")
$ContinueButtonName = _XMLGetAttrib("/MessageInfo/CBN", "ContinueButtonName")
$Scheduler = _XMLGetAttrib("/MessageInfo/Sched", "Scheduler")

_Main()

; Functions
Func _Main()
    Local $msg, $AbortButton, $ContinueButton, $ScheduleBox
    $hGUI = GUICreate($FormTitle, $Width - 20, $Height - 100, -1, 10, -1)
    $hRichEdit = _GUICtrlRichEdit_Create($hGUI, "", 10, 10, $Width - 40, $Height - 150, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    ;GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    _GUICtrlRichEdit_SetEventMask($hRichEdit, $ENM_LINK)
    _GUICtrlRichEdit_AutoDetectURL($hRichEdit, True)
    $ContinueButton = GUICtrlCreateButton($ContinueButtonName, $Width - 500, $Height - 133, 100, 25)
    GUICtrlSetFont($ContinueButton, 10, 800, 0, "Tahoma")
    $AbortButton = GUICtrlCreateButton($AbortButtonName, $Width - 390, $Height - 133, 100, 25)
    GUICtrlSetFont($AbortButton, 10, 800, 0, "Tahoma")
    $ScheduleBox = GUICtrlCreateCheckbox("Defer", $Width - 280, $Height - 133, 75, 25)
    GUICtrlSetFont($ScheduleBox, 10, 800, 0, "Tahoma")

    Global $hCombo = GUICtrlCreateCombo("", $Width - 200, $Height - 132, 90, 25)
    GUICtrlSetData(-1, @HOUR + 1 & "|" & @HOUR + 2 & "|" & @HOUR + 3 & "|" & @HOUR + 4 & "|" & @HOUR + 5 & "|" & @HOUR + 6 & "|" & @HOUR + 7 & "|" & @HOUR + 8)

    $GoButton = GUICtrlCreateButton("Go", $Width - 75, $Height - 133, 50, 25)
    GUICtrlSetFont($GoButton, 10, 800, 0, "Tahoma")

    GUISetState()
    _GUICtrlRichEdit_StreamFromFile($hRichEdit, $RTFName)
    _GUICtrlRichEdit_SetReadOnly($hRichEdit)
    _GUICtrlRichEdit_GotoCharPos($hRichEdit, 0)
    MouseClick("main", @DesktopWidth / 2, @DesktopHeight / 2, 0)
    Sleep(1000)
    ;GUISetState(@SW_MINIMIZE)
    GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $ContinueButton
                Opt("TrayIconHide", 1)
                GUISetState(@SW_HIDE)
                $ExitCode = RunWait(@ScriptDir & "\" & $ProgramName)
                _GUICtrlRichEdit_Destroy($hRichEdit)
                ;MsgBox(0, "Program Exit Code", $ExitCode)
                Exit $ExitCode
            Case $msg = $GoButton
                Opt("TrayIconHide", 1)
                GUISetState(@SW_HIDE)
                ;Scheduler()
                _GUICtrlRichEdit_Destroy($hRichEdit)
                Exit
            Case $msg = $GUI_EVENT_CLOSE Or $msg = $AbortButton
                _GUICtrlRichEdit_Destroy($hRichEdit)
                Exit -1
        EndSelect
    WEnd
EndFunc   ;==>_Main

;~ Func Scheduler()
;~  Local $sXtra_Parms
;~  Local $sDateTime = _DateAdd('h', $sHours, _NowCalc())
;~  Local $sStartDate = StringMid($sDateTime, 6, 3) & StringMid($sDateTime, 9, 2) & "/" & StringLeft($sDateTime, 4)
;~  $sStartTime = StringRight($sDateTime, 8)

;~  If @OSVersion = "WIN_VISTA" Or @OSVersion = "WIN_7" Or @OSVersion = "WIN_8" Then $sXtra_Parms = " /Z /V1"

;~  Local $QueryTask = Run("SCHTASKS /QUERY /TN " & $FormTitle, "", @SW_HIDE, $STDOUT_CHILD)

;~  Local $line = ""

;~  While 1
;~      $line &= StdoutRead($QueryTask)
;~      If @error Then ExitLoop
;~  WEnd

;~  If $line = "" Then
;~      $sCmd = 'SCHTASKS /CREATE /SC ONCE /TN ' & $FormTitle & ' /TR ' & $ProgramName & ' /SD ' & $sStartDate & ' /ST ' & $sStartTime & ' /RU SYSTEM' & $sXtra_Parms
;~      Run($sCmd, "", @SW_HIDE)
;~      ;MsgBox(0, "", $sCmd) ; for testing
;~  Else
;~      $sCmd = 'SCHTASKS /CHANGE /TN ' & $FormTitle & ' /SD ' & $sStartDate & ' /ST ' & $sStartTime
;~      Run($sCmd, "", @SW_HIDE)
;~      ;MsgBox(0, "", $sCmd) ; for testing
;~  EndIf
;~ EndFunc   ;==>Scheduler

Here is the Config.xml file if you're interested.

<?xml version="1.0"?>
<MessageInfo>
    <Title FormTitle="EMET 4.1"/>
    <Display RTFName="RichText.rtf"/>
    <Program ProgramName="Emet installer.exe /sccm"/>
    <TrayTip TrayTip="EMET 4.1 Available"/>
    <ShutdownTimer ShutdownTimer="300000"/>
    <Param ParamName=""/>
    <Abort AbortAllowed="Y" />
    <ABN AbortButtonName="Not Now"/>
    <CBN ContinueButtonName="Continue"/>
    <Sched Scheduler="0"/>
</MessageInfo>
Edited by mdwerne

Share this post


Link to post
Share on other sites



Anyone have any suggestions on this, I've been poking at this for a couple days and not really making any progress.

If the mess above is too confusing, I can simplify and restate.

Thanks for taking a look,

-Mike

Share this post


Link to post
Share on other sites

Okay...I was left to my own devices long enough and actually came up with something, not pretty, but it seems to work.

(?) My question now is, where is the "0" coming from at the end of my ComboBox, and do I remove the "0". (?)

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <Date.au3>

Global $CurrentTime, $i, $AMPM

If @HOUR > 12 Then
    $AMPM = "PM"
ElseIf @HOUR = 0 Then
    $AMPM = "AM"
Else
    $AMPM = "AM"
EndIf

GUICreate("ComboTest", 200, 40)
Global $hCombo = GUICtrlCreateCombo("New install time:", 10, 10, 180, 25)
GUICtrlSetData(-1, GetTimes())
GUISetState()
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Func GetTimes()
    Local $CurrentHour = StringTrimRight(_NowTime(), 9)
    For $i = $CurrentHour To 11 Step +1
        _GUICtrlComboBox_BeginUpdate($hCombo)
        _GUICtrlComboBox_InsertString($hCombo, $i & ":00 " & $AMPM, -1)
        _GUICtrlComboBox_InsertString($hCombo, $i & ":30 " & $AMPM, -1)
        _GUICtrlComboBox_EndUpdate($hCombo)
    Next
EndFunc   ;==>GetTimes

Thanks for your time,

-Mike

Share this post


Link to post
Share on other sites

GetTimes() returns 0 so do not use GUICtrlSetData to add the return value of 0 to the combo.

Updated code

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <Date.au3>

Global $CurrentTime, $i, $AMPM

If @HOUR > 12 Then
    $AMPM = "PM"
ElseIf @HOUR = 0 Then
    $AMPM = "AM"
Else
    $AMPM = "AM"
EndIf

GUICreate("ComboTest", 200, 40)
Global $hCombo = GUICtrlCreateCombo("New install time:", 10, 10, 180, 25)
; function returns value of 0
GetTimes()
GUISetState()
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Func GetTimes()
    Local $CurrentHour = StringTrimRight(_NowTime(), 9)
    _GUICtrlComboBox_BeginUpdate($hCombo)
    For $i = $CurrentHour To 11
        _GUICtrlComboBox_InsertString($hCombo, $i & ":00 " & $AMPM, -1)
        _GUICtrlComboBox_InsertString($hCombo, $i & ":30 " & $AMPM, -1)
    Next
    _GUICtrlComboBox_EndUpdate($hCombo)
EndFunc   ;==>GetTimes
1 person likes this

Share this post


Link to post
Share on other sites

Thanks MHz, your correction and code clean up helped me learn a bit more.

All the best!

-Mike

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

  • Similar Content

    • IAMK
      By IAMK
      Hello,
       
      I have a script which uses a GUI with two buttons. It gets shown and hidden., and pressing the buttons (including their hotkeys) highlights the button, making you able to press enter the next time.
      However, I don't want that.
       
      I've tried using WinActivate() to make enter do things on another program, but the enter is still tied to the AutoIT GUI (which still has the button highlighted).
       
      Here's the important part of my code:
      $MY_GUI = GUICreate("Check.exe", 400, 300, ((@DesktopWidth / 2) - 200), -500) WinSetOnTop($MY_GUI, "", 1) ;Keeps the window on the top. $Button1 = GUICtrlCreateButton("Pass (Ctrl+P)", 40, 250, 120, 40, $WS_GROUP) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Button2 = GUICtrlCreateButton("Fail (Ctrl+F)", 240, 250, 120, 40, $WS_GROUP) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $GUIText = GUICtrlCreateLabel("", 20, 10, 360, 230) GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif") GUICtrlSetData($GUIText, Execute($stepMessage[$step])) $showGUI = "True" GUISetState(@SW_SHOW) While($showGUI = "True") $buttonPressed = GUIGetMsg() Switch $buttonPressed Case $Button1 ;Pass $pass = "True" $buttonPressed = 0 $showGUI = "False" GUISetState(@SW_HIDE) Case $Button2 ;Fail $buttonPressed = 0 $showGUI = "False" GUISetState(@SW_HIDE) While($message = "") $message = InputBox("Check.exe", "Please enter the reason the step failed." & @CRLF, "", "", 300, 200, ((@DesktopWidth / 2) - 150), -400) WEnd Return $message EndSwitch WEnd Local $pass = "False" ;Whether "Pass" or "Fail" was pressed. Local $failLog = xxxfunc($pass) ;Returns a message to log if the step failed. ##THIS CALLS THE CODE SNIPPET ABOVE## FileWrite($file, _Now() & ": Step " & $step & getStatus($pass) & "and took " & Ceiling(TimerDiff($timer) / 1000) & " seconds." & @CRLF) If($failLog <> "") Then FileWrite($file, "Logged comment: " & $failLog & @CRLF) EndIf WinActivate("[TITLE:ProgramName]") ;Hotkeys: HotKeySet("^{p}", "pressPass") HotKeySet("^{f}", "pressFail") Func pressPass() $buttonPressed = $Button1 EndFunc Func pressFail() $buttonPressed = $Button2 EndFunc  
      The GUI's button/hotkey pressing works correctly.
      The same WinActivate code works in another script of mine.
      Together, WinActivate is not take "Active" away from the GUI's last-pressed button. How do I fix this?
       
      Thank you in advance.
    • fatpig
      By fatpig
      Dear AutoIT Community.
      I am currently working on a program that will display lots of images in a scroll down GUI.
      I create the GUI based on the number of images, which works fine.
      But all images I place using GuiCtrlCreatePic above a threshold of around 32000 pixels (cant say exactly) are placed at negative locations and finally will reach 0 again
      and will then populate on top of the images placed there before.
      For $i = 1 To $Images[0] ; Get picture dimensions $hImage = _GDIPlus_ImageLoadFromFile($ImgRep & $Images[$i]) $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) _GDIPlus_ImageDispose($hImage) ; Resize & place images in GUI $Pic[$i] = GUICtrlCreatePic($ImgRep & $Images[$i], $Spacer, Round($yPos, 0), $MaxImgWidth, $MaxImgWidth * ($iY / $iX)) $yPos = $yPos + $MaxImgWidth * ($iY / $iX) + $Spacer $log = $log & "|" & $yPos $currentlut = $Images[1] Next I have found a limit at 32767 pixels for some GUI elements when googling around.
      Can someone tell me how to circumvent that?
      thanks!
      cheers
      Felix
    • Ian_Mac
      By Ian_Mac
      hello, i just wanted to ask if how........
       I have a gui combo box with a list and i wanted it to remember the last item that i selected, that when i close the gui and then open the gui again, my last selected item will be automatically show in the combobox as selected item already.
      thank you in advance.
    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Guys this is my gui and i need the numeric value typed in the highlighted  inputbox. if this value is greater than 1 i need to perform some operations
      \
       
      Here is the summary about that field which i got from wininfo tool

      i tried writing the code as shown below.. but the msgbox is popping up empty value..when the same code is pasted under some button action i am able to access the value present in the field..but when placed alone as written in the attached script i am unable to fetch it... 

      here i am using the valu present in the field

      can you guys tell me what's wrong??? or how can i get that value?
       
      My_GUI.au3

    • Neonovaz
      By Neonovaz
      Hello
       
      Is there anyway to store word documents in Autoit GUI? For example I have a instruction sheet that I want to bundle up with the exe.

      So a user simply clicks the icon and the stored document will launch  (Something like how you can add objects like excel sheets in word documents )

      (I Know we can launch word files from script directory)