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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:53:25+00:00 2026-05-26T19:53:25+00:00

I create a Windows Service project in VS2010 that contains multiple services. I tried

  • 0

I create a Windows Service project in VS2010 that contains multiple services. I tried to cull together a way to install it without a complex installer. But, it seems to rollback and not work.

Here’s Program.cs:

static class Program
{
    static void Main(string[] args)
    {
        bool install = false, uninstall = false, console = false;
        WindowsServiceInstaller inst = new WindowsServiceInstaller();

        if (args.Length > 0)
        {
            foreach (string arg in args)
            {
                switch (arg)
                {
                    case "-i":
                    case "-install":
                        install = true;
                        break;
                    case "-u":
                    case "-uninstall":
                        uninstall = true;
                        break;
                    case "-c":
                    case "-console":
                        console = true;
                        break;
                    default:
                        Console.Error.WriteLine("Argument not expected: " + arg);
                        break;
                }
            }
        }

        if (uninstall)
        {
            inst.InstallServices(false, args);
        }

        if (install)
        {
            inst.InstallServices(true, args);
        }

        ServiceBase[] ServicesToRun;
        ServicesToRun = new ServiceBase[] 
        { 
            // scans Email table for outbound email jobs; uses multiple threads to lock and work on data in Email table
              new EmailLogScanner()

            // generates email digest of document status on secheduled basis; single thread
            , new EmailStatusDigester() 

            // keeps Fax table and third-party fax service accounts synchronized; uses a fixed nb of threads, one thread syncs one account at a time
            , new FaxSynchronizer()     
        };

        if (console)
        {

            foreach (IDebuggableService srv in ServicesToRun)
            {
                string[] strs = new string[] { String.Empty };
                srv.DebugStart(strs);
            }

            Console.WriteLine("Press any key to terminate...");
            Console.ReadKey();

            foreach (IDebuggableService srv in ServicesToRun)
            {
                srv.DebugStop();
            }

            Console.WriteLine("Service has exited.");
        }
        else
        {
            ServiceBase.Run(ServicesToRun);
        }
    }
}

Here’s WindowsServiceInstaller.cs:

[RunInstaller(true)]
public class WindowsServiceInstaller : Installer 
{
    public WindowsServiceInstaller()
    {
        ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
        serviceProcessInstaller.Account = ServiceAccount.NetworkService;
        serviceProcessInstaller.Username = null;
        serviceProcessInstaller.Password = null;
        Installers.Add(serviceProcessInstaller);

        ServiceInstaller emailLogScannerInstaller = new ServiceInstaller();
        emailLogScannerInstaller.DisplayName = "Email Scanner";
        emailLogScannerInstaller.StartType = ServiceStartMode.Automatic;
        emailLogScannerInstaller.ServiceName = "EmailLogScanner"; // must match the ServiceBase ServiceName property
        emailLogScannerInstaller.Description = "Scan for and sends out pending emails in stack.";
        Installers.Add(emailLogScannerInstaller);

        ServiceInstaller emailStatusDigesterInstaller = new ServiceInstaller();
        emailStatusDigesterInstaller.DisplayName = "Status Digester";
        emailStatusDigesterInstaller.StartType = ServiceStartMode.Automatic;
        emailStatusDigesterInstaller.ServiceName = "EmailDigester";
        emailStatusDigesterInstaller.Description = "Prepares document status email digests.";
        Installers.Add(emailStatusDigesterInstaller);

        ServiceInstaller faxSynchronizerInstaller = new ServiceInstaller();
        faxSynchronizerInstaller.DisplayName = "Fax Synchronizer";
        faxSynchronizerInstaller.StartType = ServiceStartMode.Automatic;
        faxSynchronizerInstaller.ServiceName = "FaxSynchronizer";
        faxSynchronizerInstaller.Description = "Synchronizes database with external fax service(s).";
        Installers.Add(faxSynchronizerInstaller);           

    }

    public void InstallServices(bool doInstall, string[] args)
    {
        try
        {
            using (AssemblyInstaller aInstaller = new AssemblyInstaller(typeof(Program).Assembly, args))
            {
                IDictionary state = new Hashtable();
                aInstaller.UseNewContext = true;
                try
                {
                    if (doInstall)
                    {
                        aInstaller.Install(state);
                        aInstaller.Commit(state);
                    }
                    else
                    {
                        aInstaller.Uninstall(state);
                    }
                }
                catch
                {
                    try
                    {
                        aInstaller.Rollback(state);
                    }
                    catch { }
                    throw;
                }
            }
        }
        catch (Exception ex)
        {
            Console.Error.WriteLine(ex.Message);
        }
    }

}

The logged output (when I run daemon.exe -i in a command window, as admin) shows the text below. Also, I get the “cannot start service from the command line” dialog:

Installing assembly 'C:\Users\xxx\Documents\~Business\Projects\Daemon\bin\Release\Daemon.exe'.
Affected parameters are:
   i = 
   assemblypath = C:\Users\xxx\Documents\~Business\Projects\Daemon\bin\Release\Daemon.exe
   logfile = C:\Users\xxx\Documents\~Business\Projects\Daemon\bin\Release\Daemon.InstallLog
Installing service EmailLogScanner...
Service EmailLogScanner has been successfully installed.
Creating EventLog source EmailLogScanner in log Application...
See the contents of the log file for the C:\Users\xxx\Documents\~Business\Projects\Daemon\bin\Release\Daemon.exe assembly's progress.
The file is located at C:\Users\xxx\Documents\~Business\Projects\Daemon\bin\Release\Daemon.InstallLog.
Rolling back assembly 'C:\Users\xxx\Documents\~Business\Projects\Daemon\bin\Release\Daemon.exe'.
Affected parameters are:
   logtoconsole = 
   i = 
   assemblypath = C:\Users\xxx\Documents\~Business\Projects\Daemon\bin\Release\Daemon.exe
   logfile = C:\Users\xxx\Documents\~Business\Projects\Daemon\bin\Release\Daemon.InstallLog
Restoring event log to previous state for source EmailLogScanner.
Service EmailLogScanner is being removed from the system...
Service EmailLogScanner was successfully removed from the system.

UPDATE: When I comment out the try…catch block around the ‘aInstaller.Install(state)’ line, I get a slightly different output:

Installing assembly 'C:\Users\xxx\Documents\~Business\Projects\Daemon\bin\Release\Daemon.exe'.
Affected parameters are:
   i =
   assemblypath = C:\Users\xxx\Documents\~Business\Projects\Da
emon\bin\Release\Daemon.exe
   logfile = C:\Users\xxx\Documents\~Business\Projects\Daemon\
bin\Release\Daemon.InstallLog
Installing service EmailLogScanner...
Creating EventLog source EmailLogScanner in log Application...
Source EmailLogScanner already exists on the local computer.

Is it because I already have Event Log sources setup? If so, how do I skip that step in the AssemblyInstaller? If not, wha? 🙂

  • 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-26T19:53:26+00:00Added an answer on May 26, 2026 at 7:53 pm

    You should put this

    if (EventLog.SourceExists("YourEventSourceName"))
        EventLog.DeleteEventSource("YourEventSourceName");
    

    when service installation begins.

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

Sidebar

Related Questions

I have a dot net windows service project which contains multiple services. This has
i'd like to create a windows service that would be accessible via WCF from
I'm trying to create a Windows Service in VS2010 but can't seem to add
I tried to create a OData web service using VS 2008 without any luck.
I got a setup project that installs a windows service. We are registering a
I wrote my first windows service. Create WS project Rename Service Drag a timer
I've created a Setup Project to create an installer for my Windows service I
I've created a windows service project, but I need to create another project to
I am attempting to install a C# windows service project using a VisualStudio.Net deployment
I have a windows service that references an assembly which contains the following class.

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.