kylejustknows Posted June 15, 2019 Posted June 15, 2019 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.
Developers Jos Posted June 15, 2019 Developers Posted June 15, 2019 @kylejustknows, Is this an answer to a post from 2014? Doubt that is very useful after 5 years. 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.
rudi Posted June 17, 2019 Posted June 17, 2019 (edited) wrong thread Edited June 17, 2019 by rudi Earth is flat, pigs can fly, and Nuclear Power is SAFE!
rudi Posted June 17, 2019 Posted June 17, 2019 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 Jos Posted June 17, 2019 Developers Posted June 17, 2019 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now