[PowerShell] - Graceful shutdown of a program

Solved
blux Posted messages 5044 Registration date   Status Moderator Last intervention   -  
 Luc -
Hello,

I'm looking to terminate a program normally (simulating a click on the Windows close button or File/Close/Quit from the menu) with PowerShell.

So far, I have only found stop-process. But the problem is that it performs a forceful kill of the process. Programs like Firefox don't always recover from this (message on restart regarding a possible crash).

That's why I'm looking for the method that will allow me to close it cleanly.

I also tried 'taskkill' in the command line, but it does the same kind of damage...

A command, even in vbscript, would make me happy...

Thanks in advance.

--
A+ blux
 "Fools dare to do anything. That's how we recognize them"

3 answers

  1. blux Posted messages 5044 Registration date   Status Moderator Last intervention   3 455
     
    I found (long live Google in English):

    get-process program_name | %{ $_.closemainwindow() }

    In fact, we are asking to close the main window. It just took some thought!

    --
    A+ blux
     "The fools, they dare everything. It's even how you recognize them"
    6
    1. little boy62
       
      Hi

      Is this VB?


      Catch you later and thanks for sharing your find ;)
      0
    2. blux Posted messages 5044 Registration date   Status Moderator Last intervention   3 455
       
      No, it's PowerShell...
      0
    3. little boy62
       
      Oh?


      I will look into that


      Thank you ;)
      0
  2. little boy62
     
    Hi :)

    Yes, taskkill (like processclose in AutoIt) "kills" the process...

    You basically want to simulate a left-click on the cross...

    If I find that for you in AutoIt, would that be acceptable?

    Because, I know how to simulate pressing alt+F4 in AutoIt: Is that not what you're looking for?

    Otherwise, I don't know VBScript ;)

    Anyway, good luck to you :)

    ++
    0
    1. blux Posted messages 5044 Registration date   Status Moderator Last intervention   3 455
       
      I'm looking for something standard on Windows.
      I can't install external programs, otherwise my problem would have already been solved!
      0
    2. little boy62
       
      I'm going to see if I find anything in the command line


      See you!
      0
  3. little boy62
     
    Hello

    I don't know if this can help you, but well, nothing ventured, nothing gained ;)

    https://www.generation-nt.com/reponses/fermer-application-proprement-entraide-2484831.html

    EDIT: Even in AutoIt, the fact of doing processclose, Firefox says crash ^^

    Same in command prompt...

    ++
    0
    1. Luc
       
      The syntaxes below work:

      Process:
      get-process -name chrome* -computername 127.0.0.1 | stop-process
      get-process chrome* | start-process

      Services:
      get-service -name BITS -computername 127.0.0.1 | stop-service
      get-service chrome* | start-service
      0