We help IT Professionals succeed at work.
Get Started

Close Grecefully Application With Power Shell

Akire4 asked
Last Modified: 2015-10-11
I have an application that has not Exit button but just the window UI "X" (hard to believe) and Im trying to close this application gracefully from a button the application provides by the  use  of Shell, this button has two fields to run a Shell; Command and Command Arguments.

I'm trying to run a PowerShell that when I run it on the PowerShell window work fine;

PS C:\Users\MyProfile\Desktop:> Get-Process MyApplication | Foreach-object { $_.CloseMainwindow() | Out-Null }
It closes the application and it ask if I need to save any changes when appropriate when run from Powershell console.

How can I run this Powershell from the button the application provides?

Can it be run from with in the same application I'm trying to close?

I try to save the file with a .PS1 extension and call it from the Shell button but can not make it work, what is the syntax to do this or how can I run the Powershell line from the button?
Watch Question
Messaging and Directory Services
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE