Jump to content

Recommended Posts

Posted

To FORCE terminate the process with process ID 1234:

taskkill /f /pid 1234

To gracefully terminate notepad.exe:

taskkill /im notepad.exe

The /f switch would force the kill, but not using it just sends the termination signal so the application closes gracefully.

He's right. I tried using taskkill.exe (without /f) to terminate Notepad, and it worked as expected. Notepad asked me whether or not I wanted to save the unsaved text which I'd entered.

Posted

Hi.

This "gracefull" Exit command was a Problem for me quite a while ago, too.

IIRC I "embedded" a powershell call in my Autoit Script, something like this line:

 

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

This invoced the "confirm" Dialog for regular program Exit, that I could handle with Autoit easily.

 

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

  • Developers
Posted

Since this is an AutoIt3 forum, you simply use winclose() when you want to close Notepad gracefully 🙂 :

#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Run Notepad
    Run("notepad.exe")

    ; Wait for 2 seconds to display the Notepad window.
    Sleep(2000)
    ;send("test") ;uncomment to see the confirmation box to save

    ; Close the Notepad window using the classname of Notepad.
    If WinClose("[CLASS:Notepad]", "") Then
        MsgBox($MB_SYSTEMMODAL, "", "Window closed")
    Else
        MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Window not Found")
    EndIf
EndFunc   ;==>Example

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...