Home > PowerShell > Close applications gracefully using powershell

Close applications gracefully using powershell

By saying “Graceful” close, I mean allowing the users to save any un saved data before exiting the application. It is equivalent to clicking on “CLOSE” button at the right top corner. The advantage with this method when compared “stop-process” is, it allows the user to save data and hence there is no data lose.

This option came handy to me several time.

Code:

[powershell]
Get-Process notepad | % { $_.CloseMainWindow() }
[/powershell]

The above code will get list of  notepad processes running in your PC and prompts you to save data for the processes which have unsaved content. The notepad processes which don’t have anything to save will get closed normally.

Hope this helps you…

No related content found.

  1. Noel Burgess
    May 5, 2011 at 3:29 pm | #1

    I don’t know the first thing about Powershell, although someday I hope to learn it. In the meantime, I’ve been looking for a script that will
    1. pass a ‘close’ command to a running program (wlmail.exe) (the program’s own close routine first destroys the UI, then conducts some internal housekeeping before the process ends);
    2. display a message box saying that WLMail is saving your data;
    3. remove that message box when the process ends normally.
    The script would ideally be invoked by, say, clicking a button on the desktop that is created when the wlmail.exe process starts.
    Is this feasible, do you think?

  1. No trackbacks yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>