Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 83991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:51:38+00:00 2026-05-10T21:51:38+00:00

I have a Windows Service written in Delphi which runs a number of programs.

  • 0

I have a Windows Service written in Delphi which runs a number of programs.

On Stopping the service, I want to also close these programs. When the service was originally written, this worked fine, but I think I’ve updated the tProcess component and now – The subordinate programs are not being closed.

in tProcess – Here’s the code which starts the new processes.

  if CreateProcess( nil , PChar( FProcess.Command ) , nil , nil , False ,     NORMAL_PRIORITY_CLASS , nil , Directory ,     StartupInfo , ProcessInfo ) then     begin       if FProcess.Wait then         begin           WaitForSingleObject( ProcessInfo.hProcess , Infinite );           GetExitCodeProcess( ProcessInfo.hProcess , ExitCode );           if Assigned( FProcess.FOnFinished ) then             FProcess.FOnFinished( FProcess , ExitCode );         end;       CloseHandle( ProcessInfo.hProcess );       CloseHandle( ProcessInfo.hThread );     end; 

Each of the executables called by this are Windows GUI Programs (With a close button at the top).

When I stop the service, I also want to stop (not kill) the programs I’ve started up via the createProcess procedure.

How would you do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:51:39+00:00Added an answer on May 10, 2026 at 9:51 pm

    You want to enumerate open windows that match your launched ProcessId and tell those windows to close. Here’s some sample code for that:

    uses Windows;  interface     function MyTerminateAppEnum(hHwnd:HWND; dwData:LPARAM):Boolean; stdcall;  implementation  function MyTerminateAppEnum(hHwnd:HWND; dwData:LPARAM):Boolean;  var      vID:DWORD;  begin      GetWindowThreadProcessID(hHwnd, @vID);      if vID = dwData then      begin     PostMessage(hHwnd, WM_CLOSE, 0, 0); //tell window to close gracefully     Result := False;  //can stop enumerating       end      else      begin     Result := TRUE;  //keep enumerating until you find your id      end;  end; 

    Then you’ll want to utilize this in your code when you want to shut down the launched applications:

    Procedure TerminateMe(YourSavedProcessInfo:TProcessInformation); var   vExitCode:UINT; begin   GetExitCodeProcess(YourSavedProcessInfo.hProcess, vExitCode);   if (vExitCode = STILL_ACTIVE) then  //launched app still running..   begin     //tell it to close     EnumWindows(@MyTerminateAppEnum, YourSavedProcessInfo.dwProcessId);      if WaitForSingleObject(YourSavedProcessInfo.hProcess, TIMEOUT_VAL) <> WAIT_OBJECT_0 then     begin       if not TerminateProcess(YourSavedProcessInfo.hProcess, 0) then  //didn't close, try to terminate       begin          //uh-oh   Didn't close, didn't terminate..       end;     end;   end;   CloseHandle(YourSavedProcessInfo.hProcess);   CloseHandle(YourSavedProcessInfo.hThread); end; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Ask A Question

Stats

  • Questions 58k
  • Answers 58k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer It could be that the problem is in the included… May 11, 2026 at 8:52 am
  • added an answer Your question is regarding a List<T>, which does maintain order.… May 11, 2026 at 8:52 am
  • added an answer I already know that ant is a 'build automation software',… May 11, 2026 at 8:52 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.