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 7614301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:22:10+00:00 2026-05-31T02:22:10+00:00

I’m looking and trying to install my console application as service but not figured

  • 0

I’m looking and trying to install my console application as service but not figured out how to do it.

any recommendation ?

actually i just wanted to install as service and start automatically each time windows starts or delay start

program Project1;

  Uses
  Windows,
  SysUtils,
  Dialogs,
  Messages,TlHelp32,Classes, Graphics, Controls, SvcMgr,ExtCtrls;

 Const
  SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5));
  SECURITY_BUILTIN_DOMAIN_RID = $00000020;
  DOMAIN_ALIAS_RID_ADMINS = $00000220;

  type
  TService1 = class(TService)
  private
  public
    function GetServiceController: TServiceController; override;
  end;


  var
  Service1: TService1;
  Msg: TMsg;

 Procedure ServiceController(CtrlCode: DWord); stdcall;
  begin
   Service1.Controller(CtrlCode);
 end;


 Function TService1.GetServiceController: TServiceController;
  begin
    Result := ServiceController;
 end;

Function IsAdmin: Boolean;
var
  hAccessToken: THandle;
  ptgGroups: PTokenGroups;
  dwInfoBufferSize: DWORD;
  psidAdministrators: PSID;
  x: Integer;
  bSuccess: BOOL;
begin
  Result   := False;
  bSuccess := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True,
    hAccessToken);
  if not bSuccess then
  begin
    if GetLastError = ERROR_NO_TOKEN then
      bSuccess := OpenProcessToken(GetCurrentProcess, TOKEN_QUERY,
        hAccessToken);
  end;
  if bSuccess then
  begin
    GetMem(ptgGroups, 1024);
    bSuccess := GetTokenInformation(hAccessToken, TokenGroups,
      ptgGroups, 1024, dwInfoBufferSize);
    CloseHandle(hAccessToken);
    if bSuccess then
    begin
      AllocateAndInitializeSid(SECURITY_NT_AUTHORITY, 2,
        SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
        0, 0, 0, 0, 0, 0, psidAdministrators);
      {$R-}
      for x := 0 to ptgGroups.GroupCount - 1 do
        if EqualSid(psidAdministrators, ptgGroups.Groups[x].Sid) then
        begin
          Result := True;
          Break;
        end;
      {$R+}
      FreeSid(psidAdministrators);
    end;
    FreeMem(ptgGroups);
  end;
end;

begin

 if IsAdmin then
   begin
                 // Install me as service 
   end else
 begin
    ShowMessage('Not Running As Admin');
 end;


  while GetMessage(Msg, 0, 0, 0) do
   begin
   TranslateMessage(Msg);
   DispatchMessage(Msg);
  end;

end.
  • 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. Editorial Team
    Editorial Team
    2026-05-31T02:22:11+00:00Added an answer on May 31, 2026 at 2:22 am

    There are at least two ways: one of these is the ‘right’ way, and one is ‘wrong’ (but works.)

    The wrong-but-works way

    You can run any application as a service through (host) helper utilities, such as:

    • ServiceEx, “a freeware Windows application that allows a normal program to run as a Windows service”. I have never used this, I just found it through Googling.
    • One of two utilities Microsoft provides (Since it’s from MS, I would use this one.)

    Why is this the wrong way? Because if you want your application to run as a service, you should create a service app. And it just so happens that that’s very easy with Delphi. This is the right way:

    The right way: create a service app

    This delphi.about.com article has a lot of information about service applications. However, it’s fairly simple: create a new service application through File > New > [perhaps Other >] Service Application. Set the display name etc. To install it, run with the command line switch /install; to uninstall run with /uninstall.

    If the reason you want your command-line app to run as a service is because you don’t want to write two applications, with good design you can minimise the extra work. In your project group have two applications, your command-line app and your service app. Then share the code in other files – i.e. write the code to do your app’s work once, and include / call it from both projects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

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.