Switchback Posted November 18, 2007 Posted November 18, 2007 Hello, im trying to make a script which can open programs (for testing it i used the notepad) and close them via a trayicon. because the windows have the same name i used the pid to close them, everytime a new notepad is opened it shall create a new entry in the closemenu with the pid, that works.... When i click on the first pid that was created it works and the process closes, but the other pid's which were created are useless cuz nothing happens when i click on them, i deleted the path with the close option in my code cuz it didnt work, i hope anyone knows a solution expandcollapse popup#Include <Constants.au3> #NoTrayIcon Opt("TrayMenuMode",1) TraySetState() $NotepadMenu =TrayCreateMenu ("Notepad") $OpenItem =TrayCreateItem ("Open",$NotepadMenu) $CloseMenu =TrayCreateMenu ("Close",$NotepadMenu) $ExitItem =TrayCreateItem ("Exit") $CloseAllItem =TrayCreateItem ("Close all",$CloseMenu) While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $OpenItem run ("notepad.exe") $list = ProcessList ("notepad.exe") TrayCreateItem ($List[$List[0][0]][1],$CloseMenu) Case $msg = $ExitItem ExitLoop Case $msg = $CloseAllItem Do Processclose ("notepad.exe") Until ProcessExists ("notepad.exe")=0 EndSelect WEnd
rasim Posted November 18, 2007 Posted November 18, 2007 (edited) Example: expandcollapse popup#Include <Constants.au3> #NoTrayIcon Opt("TrayMenuMode",1) Opt ("TrayOnEventMode", 1) TraySetState() $NotepadMenu =TrayCreateMenu ("Notepad") $OpenItem =TrayCreateItem ("Open",$NotepadMenu) TrayItemSetOnEvent(-1, "PIDAdd") $CloseMenu =TrayCreateMenu ("Close",$NotepadMenu) $ExitItem =TrayCreateItem ("Exit") TrayItemSetOnEvent(-1, "TrayExit") $CloseAllItem =TrayCreateItem ("Close all",$CloseMenu) While 1 Sleep(300) WEnd Func PIDAdd() $PID = Run("notepad.exe") TrayCreateItem($PID, $CloseMenu) TrayItemSetOnEvent(-1, "PIDClose") EndFunc Func PIDClose() $PidToKill = TrayItemGetText(@TRAY_ID) ProcessClose($PidToKill) TrayItemDelete(@TRAY_ID) EndFunc Func TrayExit() Exit EndFunc Edited November 18, 2007 by rasim
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