potitpanda Posted April 3, 2008 Posted April 3, 2008 Hi I have created a tray Icon Menu with 2 items: Close which close the program Connect Which connect to a shared folder using Net Use So when it's connected I Want the line Connect to Change as "Disconnect" without add a Line in my tray menu and when I Click on Disconnect, go to Function Disconnect() How to do this ? #include <Constants.au3> Opt("TrayOnEventMode",1) Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown. TraySetClick(16) ; Only secondary mouse button will show the tray menu. $infoitem = TrayCreateItem("Connecter...") TrayItemSetOnEvent(-1,"Connecter") TrayCreateItem("") $exititem = TrayCreateItem("Fermer") TrayItemSetOnEvent(-1,"ExitScript") TraySetState() While 1 Sleep(10) ; Idle loop WEnd ; Functions Func Connecter() run("net use \\172.26.0.163\Moliere /user:AD-0133490Y\moliere moliere","",@SW_HIDE) MsgBox(0,"Connecté", "Vous etes connecté à Molière") EndFunc Func ExitScript() Exit EndFunc Func Deconnecter() Run("net use /delete \\172.26.0.163\Moliere","",@SW_HIDE) MsgBox(0,"Déconnecté", "Vous etes Déconnecté de Molière") Exit EndFunc
Monamo Posted April 3, 2008 Posted April 3, 2008 (edited) Hi I have created a tray Icon Menu with 2 items: Close which close the programConnect Which connect to a shared folder using Net Use So when it's connected I Want the line Connect to Change as "Disconnect" without add a Line in my tray menu and when I Click on Disconnect, go to Function Disconnect()How to do this ?CODE#include <Constants.au3>Opt("TrayOnEventMode",1)Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown.TraySetClick(16) ; Only secondary mouse button will show the tray menu.$infoitem = TrayCreateItem("Connecter...")TrayItemSetOnEvent(-1,"Connecter")TrayCreateItem("")$exititem = TrayCreateItem("Fermer")TrayItemSetOnEvent(-1,"ExitScript")TraySetState()While 1 Sleep(10) ; Idle loopWEnd; FunctionsFunc Connecter() run("net use \\172.26.0.163\Moliere /user:AD-0133490Y\moliere moliere","",@SW_HIDE)MsgBox(0,"Connecté", "Vous etes connecté à Molière")EndFuncFunc ExitScript() ExitEndFuncFunc Deconnecter() Run("net use /delete \\172.26.0.163\Moliere","",@SW_HIDE) MsgBox(0,"Déconnecté", "Vous etes Déconnecté de Molière")Exit EndFuncGive this a try (untested, but the basic concept is there):CODE#include <Constants.au3>Opt("TrayOnEventMode", 1)Opt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown.TraySetClick(16) ; Only secondary mouse button will show the tray menu.$connectionitem = TrayCreateItem("Connecter...")TrayItemSetOnEvent(-1, "Connecter")$iConnected = 0TrayCreateItem("")$exititem = TrayCreateItem("Fermer")TrayItemSetOnEvent(-1, "ExitScript")TraySetState()While 1 Sleep(10) ; Idle loopWEnd; FunctionsFunc Connecter() If $iConnected Then Run("net use /delete \\172.26.0.163\Moliere", "", @SW_HIDE) TrayItemSetText($connectionitem,"Débranchez...") MsgBox(0, "Déconnecté", "Vous etes Déconnecté de Molière") Else Run("net use \\172.26.0.163\Moliere /user:AD-0133490Y\moliere moliere", "", @SW_HIDE) TrayItemSetText($connectionitem,"Connect") MsgBox(0, "Connecté", "Vous etes connecté à Molière") EndIf $iConnected = Not $iConnectedEndFuncFunc ExitScript() ExitEndFunc***Edit*** Spacing Edited April 3, 2008 by Monamo - MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]
MHz Posted April 3, 2008 Posted April 3, 2008 Another way to do it. expandcollapse popup#include <Constants.au3> Opt("TrayOnEventMode",1) Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown. TraySetClick(16) ; Only secondary mouse button will show the tray menu. $infoitem = TrayCreateItem("Connecter...") TrayItemSetOnEvent(-1,"Connecter") TrayCreateItem("") $exititem = TrayCreateItem("Fermer") TrayItemSetOnEvent(-1,"ExitScript") TraySetState() While 1 Sleep(10) ; Idle loop WEnd ; Functions Func Connecter() run("net use \\172.26.0.163\Moliere /user:AD-0133490Y\moliere moliere","",@SW_HIDE) TrayItemSetText($infoitem, 'Disconnect') TrayItemSetOnEvent($infoitem, "DeConnecter") MsgBox(0,"Connecté", "Vous etes connecté à Molière") EndFunc Func ExitScript() Exit EndFunc Func Deconnecter() Run("net use /delete \\172.26.0.163\Moliere","",@SW_HIDE) MsgBox(0,"Déconnecté", "Vous etes Déconnecté de Molière") Exit EndFunc
potitpanda Posted April 4, 2008 Author Posted April 4, 2008 Second Method Works Fine Thanks PS : I Will test the first method Later
Recommended 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 accountSign in
Already have an account? Sign in here.
Sign In Now