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

  • SEARCH
  • Home
  • 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 63557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:39:05+00:00 2026-05-10T18:39:05+00:00

I have a standard .NET windows service written in C#. Can it install itself

  • 0

I have a standard .NET windows service written in C#.

Can it install itself without using InstallUtil? Should I use the service installer class? How should I use it?

I want to be able to call the following:

MyService.exe -install 

And it will have the same effect as calling:

InstallUtil MyService.exe 
  • 1 1 Answer
  • 1 View
  • 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-10T18:39:05+00:00Added an answer on May 10, 2026 at 6:39 pm

    Yes, that is fully possible (i.e. I do exactly this); you just need to reference the right dll (System.ServiceProcess.dll) and add an installer class…

    Here’s an example:

    [RunInstaller(true)] public sealed class MyServiceInstallerProcess : ServiceProcessInstaller {     public MyServiceInstallerProcess()     {         this.Account = ServiceAccount.NetworkService;     } }  [RunInstaller(true)] public sealed class MyServiceInstaller : ServiceInstaller {     public MyServiceInstaller()     {         this.Description = 'Service Description';         this.DisplayName = 'Service Name';         this.ServiceName = 'ServiceName';         this.StartType = System.ServiceProcess.ServiceStartMode.Automatic;     } }  static void Install(bool undo, string[] args) {     try     {         Console.WriteLine(undo ? 'uninstalling' : 'installing');         using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, args))         {             IDictionary state = new Hashtable();             inst.UseNewContext = true;             try             {                 if (undo)                 {                     inst.Uninstall(state);                 }                 else                 {                     inst.Install(state);                     inst.Commit(state);                 }             }             catch             {                 try                 {                     inst.Rollback(state);                 }                 catch { }                 throw;             }         }     }     catch (Exception ex)     {         Console.Error.WriteLine(ex.Message);     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have built a .NET Windows Service that we install on client PCs to
I have an ASP.NET 3.5 Web Site using the standard SQL Membership Provider. The
I have a windows service (.net) that is an implementation of a custom protocol.
I have the VS2005 standard edition and MS says this: Note: The Windows Service
I have a multi-language windows application that uses standard .net localization in resx files.
I have a Windows Service developed in C# and .NET 3.5 to perform various
We have a Windows Service created in .Net 4.0, the services parses large text
We have created a .NET 4 web service, which runs fine on a Windows
I have the WCF REST Service target to .NET Framework 4. I am using
I have a standard ASP.NET 2.0 web page with a Delete button on it.

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.