473,398 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Sending Ctrl+C to Apache

I am in a pickel, I MUST start and stop the apache web server in
console mode. The only way to shut down apache cleaning is by
pressing <Ctrl>+C. I have tried everything I know and I cannot
duplicate that in C# code. This is what I have, which is NOT working:

[DllImport("Kernel32.dll")]
public static extern bool GenerateConsoleCtrlEvent(int ctrlEvent, int
processGroupId);
[DllImport("Kernel32.dll")]
public static extern int GetProcessId(IntPtr Process);

int processID = GetProcessId(process.Handle);
GenerateConsoleCtrlEvent(0, processID);

Of course, process IS the apache service the application started.
Anyone have any more thoughts?

Feb 2 '07 #1
4 6366
Have you tried:
System.Windows.Forms.SendKeys?

eg:
IWshRuntimeLibrary.WshShell Shell;

Shell.Run("calc");
Threading.Thread.Sleep(100);
Shell.AppActivate("Calculator");
Shell.SendKeys("101")
Sleep(500);
Shell.SendKeys("*");

or you could show it some tough love:
Process[] Processes = Process.GetProcessesByName("apache");
foreach( Process myProcess in Processes)
{
myProcess.CloseMainWindow(); //not so tough...
myProcess.Kill(); //Oh dear...... You can just imagin what this does.

}

I dont think PInvokes are required, but let me know how it goes :)

"ca******@gmail.com" wrote:
I am in a pickel, I MUST start and stop the apache web server in
console mode. The only way to shut down apache cleaning is by
pressing <Ctrl>+C. I have tried everything I know and I cannot
duplicate that in C# code. This is what I have, which is NOT working:

[DllImport("Kernel32.dll")]
public static extern bool GenerateConsoleCtrlEvent(int ctrlEvent, int
processGroupId);
[DllImport("Kernel32.dll")]
public static extern int GetProcessId(IntPtr Process);

int processID = GetProcessId(process.Handle);
GenerateConsoleCtrlEvent(0, processID);

Of course, process IS the apache service the application started.
Anyone have any more thoughts?

Feb 2 '07 #2
On Feb 1, 10:12 pm, TheMadHatter
<TheMadHat...@discussions.microsoft.comwrote:
Have you tried:
System.Windows.Forms.SendKeys?

eg:
IWshRuntimeLibrary.WshShell Shell;

Shell.Run("calc");
Threading.Thread.Sleep(100);
Shell.AppActivate("Calculator");
Shell.SendKeys("101")
Sleep(500);
Shell.SendKeys("*");

or you could show it some tough love:
Process[] Processes = Process.GetProcessesByName("apache");
foreach( Process myProcess in Processes)
{
myProcess.CloseMainWindow(); //not so tough...
myProcess.Kill(); //Oh dear...... You can just imagin what this does.

}

I dont think PInvokes are required, but let me know how it goes :)
I was doing the last thing you suggested, already, that is getting the
process by name and killing them all. The downside to that was that I
also had a develpment instance running as a service and it, too, was
killed.

What I had missed what the CloseMainWindow() call, this works like a
charm! The whole deal is that when you start one instance of apache,
it starts one or more children. When you Kill() the process you
started, the children keep running. But CloseMainWindow() sends the
right info to the parent apache and it closes the other servers
gracefully!

Thanks!

Feb 3 '07 #3

You were trying to kill children eh? LOL !!!

Anyhoo.....
Glad to be of some assistance.

"herc" wrote:
On Feb 1, 10:12 pm, TheMadHatter
<TheMadHat...@discussions.microsoft.comwrote:
Have you tried:
System.Windows.Forms.SendKeys?

eg:
IWshRuntimeLibrary.WshShell Shell;

Shell.Run("calc");
Threading.Thread.Sleep(100);
Shell.AppActivate("Calculator");
Shell.SendKeys("101")
Sleep(500);
Shell.SendKeys("*");

or you could show it some tough love:
Process[] Processes = Process.GetProcessesByName("apache");
foreach( Process myProcess in Processes)
{
myProcess.CloseMainWindow(); //not so tough...
myProcess.Kill(); //Oh dear...... You can just imagin what this does.

}

I dont think PInvokes are required, but let me know how it goes :)

I was doing the last thing you suggested, already, that is getting the
process by name and killing them all. The downside to that was that I
also had a develpment instance running as a service and it, too, was
killed.

What I had missed what the CloseMainWindow() call, this works like a
charm! The whole deal is that when you start one instance of apache,
it starts one or more children. When you Kill() the process you
started, the children keep running. But CloseMainWindow() sends the
right info to the parent apache and it closes the other servers
gracefully!

Thanks!

Feb 5 '07 #4
Actually, I ran into another interesting issue. When I launch apache
and tell it to hide the process window, CloseMainWindow() does nothing:
( I am assuming it is because there is no main window to close. Oh
well, I will simply minimize the window for early testing and before
release I will fix apache! The docs claim that you can lanuch another
instance to kill the one running, but it doesn't work, I will change
that! hehehehe

On Feb 5, 3:08 pm, TheMadHatter
<TheMadHat...@discussions.microsoft.comwrote:
You were trying to kill children eh? LOL !!!

Anyhoo.....
Glad to be of some assistance.

"herc" wrote:
What I had missed what the CloseMainWindow() call, this works like a
charm! The whole deal is that when you start one instance of apache,
it starts one or more children. When you Kill() the process you
started, the children keep running. But CloseMainWindow() sends the
right info to the parent apache and it closes the other servers
gracefully!
Thanks!

Feb 12 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Per Magnus L?vold | last post by:
Hi, I am working with a simple Java program which communicates over the serial port with a GSM modem. Using Hypertermial, I can send messages and need to press control-z to process the messages....
4
by: Scott | last post by:
I am using a TCPIP connection to communicate over port 23 (telnet) to a server, and I am having to mimic normal command line interface you owuld see in a telnet session (i.e. I have to write to...
5
by: PerryG | last post by:
We have a .NET 1.1 client which is sending a gzipped soap request using HttpWebRequest to an Apache server. The Apache server is using a the 'mod_deflate' server to decompress the incoming...
3
by: s99999999s2003 | last post by:
hi i have a program that works very similar to tail -f in Unix It will need a Ctrl-C in order to break out of the program. I wish to run this program using python (either thru os.system() or some...
2
by: s99999999s2003 | last post by:
hi i have a program that works very similar to tail -f in Unix It will need a Ctrl-C in order to break out of the program. I wish to run this program using python (either thru os.system() or some...
3
by: Daniel Clark | last post by:
I have a Windows command line based application that only shuts down cleanly if it sees "CTRL-C" on the console. I need to automate the running of this application, but still allow the user sitting...
1
rhitam30111985
by: rhitam30111985 | last post by:
Hi all .. i am trying to do something really weird ... here is my code : import os os.system("mail -s test xxx@gmail.com asdaskdjkasdaasdad")
31
by: happyse27 | last post by:
Hi All, I am trying for weeks how to send email from windows pc, which from my gmail account to my hotmail account. Using net::smtp module sending email failed,Kindly assist. (for the item d it...
2
by: ksheerasagar17 | last post by:
Hello All, Scenario: Sending an image through webservice as byte array to an Java webservice. The Problem1: The webservice method image property expects (data type) SByte rather than Byte...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.