How to soft (!) exit a program from command line? Simulating "close" button click

  • Thread starter Thread starter Michael Walsh
  • Start date Start date
M

Michael Walsh

Assume I have a running program myprog.exe.

Ok I could exit this program from TaskManager.

But I want to do this from command line.
Furthermore I want to perform a "soft" exit which means I don't want to kill
the process immediately in the middle of a possible processing.
Instead I want to simulate a click on the close button( "X") in the upper right corner.
the program should have the possibility to do some clean up task before it exits.

How can I do this ?

Michael
 
Michael said:
Assume I have a running program myprog.exe.

Ok I could exit this program from TaskManager.

But I want to do this from command line.
Furthermore I want to perform a "soft" exit which means I don't want to kill
the process immediately in the middle of a possible processing.
Instead I want to simulate a click on the close button( "X") in the upper right corner.
the program should have the possibility to do some clean up task before it exits.

How can I do this ?

Michael
Alt-F4 is the close or exit window keystroke, normally used for gui
programs.
Control-C is a cancel command normally used for console apps. But the
program has to be checking the keyboard input for this to work. I have
programs that run and do a lot of processing and only respond to the
keyboard on rare occasions. Thus its not immediate that Cntl-C works.
 
Let's assume a few variables. Your app runs with the text in the title of the
window being "My Prog". The app closes with the commands File(Alt-f), and X.
(and does not pop a dialog for are you sure, or save?)

--close.vbs--
set shell=createobject("wscript.shell")
shell.appactivate("My Prog")
shell.sendkeys "%fx"
--end file--
http://msdn2.microsoft.com/en-us/library/8c6yea83(VS.85).aspx
--
Was this helpful? Then click the "Yes" Ratings button. Voting helps the web
interface. http://www.microsoft.com/wn3/locales/help/help_en-us.htm see
''''''''rate a post''''''''

Mark L. Ferguson
 
ProcessUtility 2.03
2003 Craig Peacock
http://www.beyondlogic.org


Command Line Process Viewer/Killer/Suspender

Usage:

ProcessUtility.exe [-v] [-t] [-c]
ProcessUtility.exe [-q] [Process Name/PID] [timeout sec(optional)]
ProcessUtility.exe [-k] [-s] [-r] [Process Name/PID]
ProcessUtility.exe [-p] [Process Name/PID]
{RealTime|High|AboveNormal|Normal|BelowNormal|Low}
ProcessUtility.exe [-a] [Process Name/PID] [Mask(To Set)]

-v View Processes.
-t View Kernel and User CPU Times.
-c View Process Creation Times.
-q Send WM_CLOSE Message. Default timeout is 60 Sec
-k Kill Process. (Terminate)
-s Suspend Process.
-r Resume Suspended Process.
-p Set Process Priority.
-a Get/Set Affinity Mask of Process.

PROCUTIL -q [PID] 5


ju.c
 
uses taskkill without /F option. See help /? for details.
-> when tested on notepad with changed text, it gets the chance to
display a "save as" box.

And check "tasklist /?" too to get PID if necessary

w.b.
 
ProcessUtility 2.03
2003 Craig Peacock
http://www.beyondlogic.org


Command Line Process Viewer/Killer/Suspender

Usage:

ProcessUtility.exe [-v] [-t] [-c]
ProcessUtility.exe [-q] [Process Name/PID] [timeout sec(optional)]
ProcessUtility.exe [-k] [-s] [-r] [Process Name/PID]
ProcessUtility.exe [-p] [Process Name/PID]
{RealTime|High|AboveNormal|Normal|BelowNormal|Low}
ProcessUtility.exe [-a] [Process Name/PID] [Mask(To Set)]

-v View Processes.
-t View Kernel and User CPU Times.
-c View Process Creation Times.
-q Send WM_CLOSE Message. Default timeout is 60 Sec
-k Kill Process. (Terminate)
-s Suspend Process.
-r Resume Suspended Process.
-p Set Process Priority.
-a Get/Set Affinity Mask of Process.

PROCUTIL -q [PID] 5


ju.c
 
Back
Top