Sending Ctrl+C to Apache

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cartoper@gmail.com

    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("Kern el32.dll")]
    public static extern bool GenerateConsole CtrlEvent(int ctrlEvent, int
    processGroupId) ;
    [DllImport("Kern el32.dll")]
    public static extern int GetProcessId(In tPtr Process);

    int processID = GetProcessId(pr ocess.Handle);
    GenerateConsole CtrlEvent(0, processID);

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

  • =?Utf-8?B?VGhlTWFkSGF0dGVy?=

    #2
    RE: Sending Ctrl+C to Apache

    Have you tried:
    System.Windows. Forms.SendKeys?

    eg:
    IWshRuntimeLibr ary.WshShell Shell;

    Shell.Run("calc ");
    Threading.Threa d.Sleep(100);
    Shell.AppActiva te("Calculator" );
    Shell.SendKeys( "101")
    Sleep(500);
    Shell.SendKeys( "*");



    or you could show it some tough love:
    Process[] Processes = Process.GetProc essesByName("ap ache");
    foreach( Process myProcess in Processes)
    {
    myProcess.Close MainWindow(); //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 :)

    "cartoper@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("Kern el32.dll")]
    public static extern bool GenerateConsole CtrlEvent(int ctrlEvent, int
    processGroupId) ;
    [DllImport("Kern el32.dll")]
    public static extern int GetProcessId(In tPtr Process);
    >
    int processID = GetProcessId(pr ocess.Handle);
    GenerateConsole CtrlEvent(0, processID);
    >
    Of course, process IS the apache service the application started.
    Anyone have any more thoughts?
    >
    >

    Comment

    • herc

      #3
      Re: Sending Ctrl+C to Apache

      On Feb 1, 10:12 pm, TheMadHatter
      <TheMadHat...@d iscussions.micr osoft.comwrote:
      Have you tried:
      System.Windows. Forms.SendKeys?
      >
      eg:
      IWshRuntimeLibr ary.WshShell Shell;
      >
      Shell.Run("calc ");
      Threading.Threa d.Sleep(100);
      Shell.AppActiva te("Calculator" );
      Shell.SendKeys( "101")
      Sleep(500);
      Shell.SendKeys( "*");
      >
      or you could show it some tough love:
      Process[] Processes = Process.GetProc essesByName("ap ache");
      foreach( Process myProcess in Processes)
      {
      myProcess.Close MainWindow(); //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!

      Comment

      • =?Utf-8?B?VGhlTWFkSGF0dGVy?=

        #4
        Re: Sending Ctrl+C to Apache


        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...@d iscussions.micr osoft.comwrote:
        Have you tried:
        System.Windows. Forms.SendKeys?

        eg:
        IWshRuntimeLibr ary.WshShell Shell;

        Shell.Run("calc ");
        Threading.Threa d.Sleep(100);
        Shell.AppActiva te("Calculator" );
        Shell.SendKeys( "101")
        Sleep(500);
        Shell.SendKeys( "*");

        or you could show it some tough love:
        Process[] Processes = Process.GetProc essesByName("ap ache");
        foreach( Process myProcess in Processes)
        {
        myProcess.Close MainWindow(); //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!
        >
        >

        Comment

        • herc

          #5
          Re: Sending Ctrl+C to Apache

          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...@d iscussions.micr osoft.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!

          Comment

          Working...