[cvsnt] Best way to abort cvs.exe?

Jerzy Kaczorowski jerzyk at wndtabs.com
Mon Nov 10 22:34:06 GMT 2003


Hartmut,

> What's the best way to abort a cvs operation, i.e. give cvs.exe the
> opportunity to terminate gracefully?

As the starting point the Microsoft Knowledge Base Article - 178893 could be
used:
http://support.microsoft.com/default.aspx?scid=kb;en-us;178893

It basically suggests to post or send WM_CLOSE to the application and hope
it will quit...

For the console application it would have to have the handler to operate
properly. That is of course not working very well on Win9x applications and
it's not sure to work on NT even thought it appears to work at the moment...

TerminateProcess is a very crude way but it *will* close the application.

Sending the Ctrl-C or Ctrl+Break to the console window can be done in two
ways:
1. Using the GenerateConsoleCtrlEvent. That is supposed to work if
CREATE_NEW_PROCESS_GROUP flag is used to create new process but it doesn't
actually. It only work if called against calling process itself. There are
some implementations around that inject the thread into the remote
application and generate Ctrl+Break from within, but that is quite dangerous
and may cause side effects.

2a. Use the keyb_event and simulate the keystokes as if Ctrl+Break was
pressed. The problem with that one is that you can only do that agaisnt the
foreground window. So to close the application you need to first bring it to
the foreground, generate keystokes and then restore the previous forground
window. There is a lot of things that can go wrong in that scenario.

2b. Use the SendInput to do the same as keyb_event. That however doesn't
work on Win95 and needs Win98 at least.

There is quite a few ways to implement the controlled exit if you can make
the apllication to co-operate, e.g. posting a registered window message
which will signal the exit to the application etc. That is not very suitable
for the console applications thought.

Summarizing: There is no best way to terminate console or any other
application on Windows. What WinCvs will be using is the sequence of
attempts:
1. Send the Ctrl+Break and Ctrl+C keystokes using keyb_event and wait a
while to see if the application closes down.
2. Post the WM_CLOSE message and wait again.
3. Use TerminateProcess as a last resort to kill the child cvsnt process.

It ain't pretty but that's what we have to work with :(

Best Regards,
Jerzy

----- Original Message ----- 
From: "Hartmut Honisch" <hartmut_honisch at web.de>
To: <cvsnt at cvsnt.org>
Sent: Thursday, November 06, 2003 9:57
Subject: [cvsnt] Best way to abort cvs.exe?


> What's the best way to abort a cvs operation, i.e. give cvs.exe the
> opportunity to terminate gracefully?
>
> There are several options that I'm aware of:
>
> - Send WM_CLOSE to the console window (doesn't work on Win9x NT AFAIK)
> - User TerminateProcess()
> - Send Ctrl-C to the console window
>
> My guess is that Ctrl-C is the best choice, because cvs.exe traps Ctrl-C
and
> performs some cleanup operations before exiting. Is that right?
>
> -Hartmut




More information about the cvsnt mailing list