I have a query regarding a DOS command. I know this link is not the right place to ask queres about DOS but didnt find any another link in this forum.

I need to send Cntrol +C to a running Exe (running on Windows) using a batch file.Can Any one guide me for this.


8 Years
Discussion Span
Last Post by mittelgeek

>>Can Any one guide me for this.
As a batch file, forget it. Can't be done. There is no way to send anything to an already running program from a batch file. But you can write a C or C++ program to do that and call that program from the batch file.


Shell programming in *nix is considerably more powerful than batch processing in MS-DOS and MS-Windows. Most things you see in *nix shell programs are not possible in batch files.


Ancient Dragon is correct, there is no way of manipulating threads using batch - or in other words, there is no command redirection available under command.com which allows you to send command output from a control-c into the input thread of a running program. You would have to use a programming language with a WIndows API available so you can manipulate threads via the Kernel.


All the other posters are correct from what I can tell. If you want to access a thread of a process your out of luck unless you bust out some C/C++ code to terminate it. If you just want to kill the running process then you can try to use pskill.exe provided in the Systernals Tools. Here is the help from the tool:

PsKill v1.12 - Terminates processes on local or remote systems
Copyright (C) 1999-2005 Mark Russinovich
Sysinternals - www.sysinternals.com

Usage: pskill [-t] [\\computer [-u username [-p password]]] <process ID | name>
-t Kill the process and its descendants.
-u Specifies optional user name for login to
remote computer.
-p Specifies optional password for user name. If you omit this
you will be prompted to enter a hidden password.

Not necessarily a Ctrl+C, but it is a way to stop a process that is not owned/created by the batch file. Of course, if you are trying to send a SIGINT or SIGHUP you won't get the expected results using the above method.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.