Jump to content

[Q] Refresh Combo Reading File Without Restarting Script


 Share

Recommended Posts

Once again I am here asking for assistance, it's been awhile since I haven't been able to figure something out on my own, thank you in advance for everyone's help. So let me get to my question

My script brings up a GUI a tech enters computer name, click on REMOTE to connect to client

A list of computer names is generated to use for historical reference, this history is populated in a dropdown menu

The problem: Script has to be closed and restarted to see the most recent history in the dropdown

Is there away to refresh list without having to close and restart the script?

Dirty Script

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <File.au3>
#include <ComboConstants.au3>

Local $msg

GUICreate ( "SCCM Remote Control", 325, 250 )
GUISetState(@SW_SHOW)
GUISetFont ( 12, 400, 1, "Calibri" )

;~ Computer Name
GUICtrlCreateGroup ( "", 10, 5, 305, 83)
GUIStartGroup()
GUICtrlCreateLabel ( "Computer Name:", 20, 25, 200, 20, $SS_LEFT)
$CompName = GUICtrlCreateInput( '', 150, 24, 150, 20 )

;~ ComboBox
$FILE = FileOpen( @ScriptDir & '\RemoteHistory')
$LINE = FileRead($FILE)
FileClose ($FILE)
GUICtrlCreateGroup ( "", 10, 85, 305, 60 )
GUIStartGroup()
GUICtrlCreateLabel ( "Remote History:", 20, 105, 200, 20, $SS_LEFT)
$History = GUICtrlCreateCombo ( '', 150, 105, 150, -1 )
GUICtrlSetData(-1, $LINE, "text3")

GUICtrlCreateGroup ( '', 110, 43, 112, 34 )
GUIStartGroup()
$ClickRemote = GUICtrlCreateLabel ( "Remote Control", 115, 55, 102, 20, $SS_LEFT )
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetCursor(-1, 0)
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GUISetState()
GUISetState(@SW_SHOW); will display an empty dialog box
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()
Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
Local $iIDFrom = BitAND($wParam, 0xFFFF);LoWord
Switch $iIDFrom
Case $ClickRemote
If GUICtrlRead($CompName) = "" Then
MsgBox ( 48, 'Empty Computer Name', 'Computer Name is empty' & @CRLF & 'Enter Computer Name and try again...' )
Else
FileOpen ( @ScriptDir & '\RemoteHistory', 1 )
_FileWriteToLine ( @ScriptDir & '\RemoteHistory', 1, GUICtrlRead($CompName) & '|', 0)
FileClose ( @ScriptDir & '\RemoteHistory' )
Run ( @ScriptDir & '\remote\CmRcViewer.exe ' & GUICtrlRead($CompName) )
EndIf
EndSwitch
EndFunc
Link to comment
Share on other sites

Hi,

You can use the _GUICtrlComboBox functions to manage the combo items (like _GUICtrlComboBox_AddString) OR you can set the data of the combo to empty and then set the content of the combo like when you start your script.

But it's too easy, I'm maybe missing something?

Br, FireFox.

Link to comment
Share on other sites

@Elephant007

C'mon... it's not a problem of understanding AutoIt.

;NOT TESTED

;connection to computer successful
_GUICtrlComboBox_InsertString($History, $lastcomputerID, 0)
$sHistory &= $lastcomputerID & "|"

FileWrite(..., StringTrimRight($sHistory, 1))


;retreive history list
$sHistory = FileRead(...) ;better to save data in INI files.
GUICtrlSetData($History, $sHistory, StringLeft($sHistory, StringInStr($sHistory, "|") -1))

Br, FireFox.

Link to comment
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
 Share

  • Recently Browsing   0 members

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