473,388 Members | 1,213 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,388 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 6364
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.