![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Exit Notification Area App Gracefully Hi, I want to use a PowerShell script to exit a Notification Area app gracefully. I've tried the obvious commands - TaskKill.exe and TSKill, and neither suits my purpose. This is because they either forcibly terminate the app (ungracefully), or just close any open window, but leave the app running in the notification area (system tray / systray). What I want to do is equivalent to right-clicking the app's notification area icon and selecting 'exit', but this must be done programmatically. Any help would be gratefully appreciated. -- Paul Anderson |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: Exit Notification Area App Gracefully Hi Sending a friendly 'Close' message to its System menu should do it eg #-------------------------- Function CloseApp { param([string]$Name=$(Throw "Please specify an application name")) $processes=[System.Diagnostics.Process]::GetProcessesByName($Name) foreach ($Process in $Processes) { $hwnd=$process.MainWindowHandle $WM_SYSCOMMAND = 0x0112 $SC_CLOSE = 0xF060 if($hwnd){ [void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null $message=[System.Windows.Forms.Message]::Create($hwnd,$WM_SYSCOMMAND,$SC_CLOSE,0) $nativeWindow=new-object System.Windows.Forms.NativeWindow $nativeWindow.DefWndProc([ref]$message) $nativeWindow=$null } } #Each process } #Function #-------------------------- CloseApp "notepad" CloseApp -Name "sapisvr" -- Jon "huddie" <paul.1.anderson.NOSPAM@xxxxxx> wrote in message news:BDE233CD-DD7A-4C90-9168-DF5406007F3D@xxxxxx
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||||||||||||||
| Guest | Re: Exit Notification Area App Gracefully You'll probably need to play with that a bit. Only works if there's a visible window ...... -- Jon "Jon" <Email_Address@xxxxxx> wrote in message news:eStQYaE3IHA.2580@xxxxxx
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #4 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Exit Notification Area App Gracefully Many thanks Jon. You're right. It only closes an open app window. It doesn't exit the app. Basically, it minimises to the systray. Same as using the taskkill /im imagename command. I was wondering is there a message I can send to the app to *exit*. Would WM_QUIT work ? Even if it would, I'm no programmer, so don't know how your code could be adapted to do this. Could you help me by giving me some idea how I could use something like this to close down apps in the system tray ? Basically a File / Exit application exit. -- -- Paul Anderson "Jon" wrote:
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #5 (permalink) | ||||||||||||
| Guest | Re: Exit Notification Area App Gracefully "huddie" <paul.1.anderson.NOSPAM@xxxxxx> wrote in message news:F5EFEC43-05B3-41C2-A2BC-35B63965F9FC@xxxxxx
Hi Huddie This may be a better approach. I do something similar to this to control the behaviour of the sidebar in Vista. If you're the one who initially starts an application, then you can keep a hold on it, so to speak, and then terminate it (hopefully) gracefully when appropriate. #Start an application $WshShell = New-Object -ComObject "WScript.Shell" $oExec = $WshShell.Exec('notepad.exe') $oExec = $WshShell.Exec('C:\Program Files\Windows Sidebar\sidebar.exe') #Close it later #start-sleep 10 $oExec.Terminate() $WshShell = $oExec = $null I think this uses wm_close messages under the hood, and seems to work better with systray icons from what I can see. Hope that helps anyhow. -- Jon | ||||||||||||
My System Specs![]() | |||||||||||||
| | #6 (permalink) | ||||||||||||
| Guest | Re: Exit Notification Area App Gracefully "Jon" <Email_Address@xxxxxx> wrote in message news:%23bat6CG3IHA.2348@xxxxxx
$WshShell = New-Object -ComObject "WScript.Shell" #$oExec = $WshShell.Exec('notepad.exe') $oExec = $WshShell.Exec('C:\Program Files\Windows Sidebar\sidebar.exe') -- Jon | ||||||||||||
My System Specs![]() | |||||||||||||
| | #7 (permalink) | ||||||||||||||||||||||||
| Guest | Re: Exit Notification Area App Gracefully On Jul 2, 5:32*pm, "Jon" <Email_Addr...@xxxxxx> wrote:
terminating the apps using WSH. Thanks for the tip! | ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Task Bar Notification area | Fred S ***** | Vista General | 1 | 07-19-2008 11:06 AM |
| Network in the notification area | Christoph Boget | Vista General | 1 | 07-09-2008 01:16 PM |
| notification area | JHC | Vista General | 4 | 05-07-2008 05:21 PM |
| taskbar Notification area | JeBuchanan | Vista General | 1 | 04-28-2008 07:12 AM |
| Notification Area | spjr2 | Vista General | 10 | 10-18-2007 05:38 PM |