Sign in to follow this  
Followers 0
Xenophane

Create Tray "Menu" on the fly

6 posts in this topic

I have created a small Tray application (with the new Beta) with some hardcoded TrayCreateItems that starts a MSTSC connection to several of our servers. But this is not very pratical since I have to hardcode all serves.

Is there a way to do this on the fly i.e read an .ini file and create the "Tray Menu" accordingly ?

Share this post


Link to post
Share on other sites



Not exactly sure what you are asking. Are you asking if it is possible for autoit to read the different server configurations from an ini file? If so, then yes, you could have it read the settings from an ini file and configure accordingly.

If you want to do something, chances are, autoit can do it.

If you want more help, please elaborate more on what exactly you want autoit to do. Perhaps paste some code or write some pseudo code of exactly what it is that you want Autoit to do.


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

Ok I will try to explain it a bit better...

Here is the code that I have written.

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown.

$Console    = TrayCreateMenu("Console Connect")
$Regular    = TrayCreateMenu("Regular Connect")
$clinton    = TrayCreateItem("Clinton", $Console)
$mail       = TrayCreateItem("Mail", $Console)
$3BMail     = TrayCreateItem("3B Mail", $Console)
$anders     = TrayCreateItem("Anders (Print)", $Console)
$dc         = TrayCreateItem("DC (Domain Controller)", $Console)
$kornelius  = TrayCreateItem("Kornelius (DC)", $Console)
$blisand    = TrayCreateItem("Blisand (DC)", $Console)
$Triosrv    = TrayCreateItem("Trio Server", $Console)
$Hoejben    = TrayCreateItem("Højben (Web Server)", $Console)
$Gearloes   = TrayCreateItem("Gearløs (Unix Flet)", $Console)
$Raptus     = TrayCreateItem("Raptus (Firewall)", $Console)

$clinton1   = TrayCreateItem("Clinton", $Regular)
$mail1      = TrayCreateItem("Mail", $Regular)
$3BMail1    = TrayCreateItem("3B Mail", $Regular)
$anders1    = TrayCreateItem("Anders (Print)", $Regular)
$dc1        = TrayCreateItem("DC (Domain Controller)", $Regular)
$kornelius1 = TrayCreateItem("Kornelius (DC)", $Regular)
$blisand1    = TrayCreateItem("Blisand (DC)", $Regular)
$Triosrv1    = TrayCreateItem("Trio Server", $Regular)
$Hoejben1    = TrayCreateItem("Højben (Web Server)", $Regular)
$Gearloes1   = TrayCreateItem("Gearløs (Unix Flet)", $Regular)
$Raptus1     = TrayCreateItem("Raptus (Firewall)", $Regular)

TrayCreateItem("")
$aboutitem      = TrayCreateItem("About")
TrayCreateItem("")
$exititem       = TrayCreateItem("Exit")

TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $clinton
            Run("mstsc -v:Clinton  /F -console")
        Case $msg = $mail
            Run("mstsc -v:Mail  /F -console")
        Case $msg = $3BMail
            Run("mstsc -v:3bmail  /F -console")
        Case $msg = $anders
            Run("mstsc -v:anders  /F -console")
        Case $msg = $dc
            Run("mstsc -v:dc  /F -console")
        Case $msg = $kornelius
            Run("mstsc -v:kornelius  /F -console")
        Case $msg = $blisand
            Run("mstsc -v:Blisand  /F -console")
        Case $msg = $Triosrv
            Run("mstsc -v:triosrv  /F -console")
        Case $msg = $Hoejben
            Run("mstsc -v:gearloes  /F -console")
        Case $msg = $Gearloes
            Run("mstsc -v:gearloes  /F -console")
        Case $msg = $Raptus
            Run("mstsc -v:raptus  /F -console")
;-------------------------------------------------------------------------------------------------
        Case $msg = $clinton1
            Run("mstsc -v:Clinton  ")
        Case $msg = $mail1
            Run("mstsc -v:Mail  ")
        Case $msg = $3BMail1
            Run("mstsc -v:3bmail  ")
        Case $msg = $anders1
            Run("mstsc -v:anders  ")
        Case $msg = $dc1
            Run("mstsc -v:dc  ")
        Case $msg = $kornelius1
            Run("mstsc -v:kornelius  ")
        Case $msg = $blisand1
            Run("mstsc -v:Blisand  ")
        Case $msg = $Triosrv1
            Run("mstsc -v:triosrv  ")
        Case $msg = $Hoejben1
            Run("mstsc -v:hoejben  ")
        Case $msg = $Gearloes1
            Run("mstsc -v:Gearloes  ")
        Case $msg = $Raptus1
            Run("mstsc -v:Raptus  ")
        
        
        Case $msg = $aboutitem
            Msgbox(64,"about:","Tool by Claus T. Nielsen")
        Case $msg = $exititem
            ExitLoop
    EndSelect
WEnd

Exit

It created a menu point for each server I can connect to, for both a console connection and a regular connection.

But what I would really like to do is create the menu, from a text file or something else, so I do not have to go and change the sourcecode, and recompile it if I need a new server added.

Hope this makes more sense...

Share this post


Link to post
Share on other sites

Makes sense. Answer is yes.

#Include <Constants.au3>
#NoTrayIcon
Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown.
Global $server[100][3]
$data = IniReadSection ( @ScriptDir&"\servers.ini", "servers" )
$Console    = TrayCreateMenu("Console Connect")
$Regular    = TrayCreateMenu("Regular Connect")
$server[0][0] = $data[0][0]
For $i = 1 to $data[0][0]
   $server[$i][0] = TrayCreateItem($data[$i][0], $Console)
GUICtrlSetOnEvent(-1, "ServerConsole")
   $server[$i][1] = TrayCreateItem($data[$i][0], $Regular)
GUICtrlSetOnEvent(-1, "ServerRegular")
   $server[$i][2] = $data[$i][1]
Next
TrayCreateItem("")
$aboutitem      = TrayCreateItem("About")
GUICtrlSetOnEvent(-1, "About")
TrayCreateItem("")
$exititem       = TrayCreateItem("Exit")
GUICtrlSetOnEvent(-1, "Exit")
TraySetState()
while 1
sleep(1000)
wend
Func About()
   Msgbox(64,"about:","Tool by Claus T. Nielsen")
EndFunc
Func Exit()
   Exit
EndFunc
Func ServerConsole()
For $i = 1 to $server[0][0]
If $server[$i][0] = @GUI_CTRLID Then
Run("mstsc -v:"&$server[$i][2]&"  /F -console")
EndIf
Next
EndFunc
Func ServerRegular()
For $i = 1 to $server[0][0]
If $server[$i][1] = @GUI_CTRLID Then
Run("mstsc -v:"&$server[$i][2]&"  ")
EndIf
Next
EndFunc

Sample INI File:

Servers.ini

[servers]
Clinton=Clinton
DC (Domain Controller)=dc
Kornelius (DC)=kornelius

#)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Nice example nfwu.

Here is corrected your code:

#Include <Constants.au3>

Opt("TrayOnEventMode",1)
Opt("TrayAutoPause",0)
Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown.
Global $server[100][3]

$Console    = TrayCreateMenu("Console Connect")
$Regular    = TrayCreateMenu("Regular Connect")

$data = IniReadSection ( @ScriptDir&"\servers.ini", "servers" )
$server[0][0] = $data[0][0]
For $i = 1 to $data[0][0]
    $server[$i][0] = TrayCreateItem($data[$i][0], $Console)
    TrayItemSetOnEvent(-1, "ServerConsole")
    $server[$i][1] = TrayCreateItem($data[$i][0], $Regular)
    TrayItemSetOnEvent(-1, "ServerRegular")
    $server[$i][2] = $data[$i][1]
Next

TrayCreateItem("")
TrayCreateItem("About")
TrayItemSetOnEvent(-1, "DoAbout")
TrayCreateItem("")
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "DoExit")

TraySetState()

While 1
    Sleep(100)
WEnd

Func DoAbout()
    Msgbox(64,"about:","Tool by Claus T. Nielsen")
EndFunc

Func DoExit()
    Exit
EndFunc

Func ServerConsole()
    For $i = 1 to $server[0][0]
        If $server[$i][0] = @TRAY_ID Then
            Run("mstsc -v:"&$server[$i][2]&"  /F -console")
            ExitLoop
        EndIf
    Next
EndFunc

Func ServerRegular()
    For $i = 1 to $server[0][0]
        If $server[$i][1] = @TRAY_ID Then
            Run("mstsc -v:"&$server[$i][2]&"  ")
            ExitLoop
        EndIf
    Next
EndFunc
Edited by Zedna

Share this post


Link to post
Share on other sites

is there a way to update the traymenu once displayed?

i have a list/shortcut tray menu option, add shortcut and run shortcut. but i am hoping to update the tray menu after adding a shortcut. can it be done? or does it have to reload the program?, because that's what i am seeing.

thanks in advanced!

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