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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:52:00+00:00 2026-06-17T11:52:00+00:00

My C# application creates a batch script and then spawns a Process to execute

  • 0

My C# application creates a batch script and then spawns a Process to execute this script.

This application needs to run as a Windows service. Additionally I also need a standalone mode where I will indicate via a command line parameter that this should just run once and exit.

The problem is that when I run the standalone version, I can see multiple instances of the app (Launcher) getting spawned. But if I were to run it from within Visual Studio, it behaves i.e executes once and exits.

Can someone help me understand whats going on?

Here’s the class with the main()

static class Launcher
{
    static void Main(String[] args)
    {
        if(args[0] == "/standalone")
        {
            using(MyService service = new MyService())
            {
                service.StartService();
                service.StopService();
            }
        }
        else
        {
            System.ServiceProcess.ServiceBase[] ServicesToRun;
            ServicesToRun = new System.ServiceProcess.ServiceBase[] 
            { new MyService() };
            System.ServiceProcess.ServiceBase.Run(ServicesToRun);
        }
    }
}

The MyService class:

public partial class MyService : ServiceBase
{
    protected override void OnStart(string[] args)
    {
        Process p = new Process();
        p.StartInfo.FileName = "C:\abc.bat";
        p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        p.Start();
    }

    protected override void OnStop()
    {
        // Log something
    }

    public void StartService()
    { this.OnStart(null); }

    public void StopService()
    { this.OnStop() }
}
  • 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-06-17T11:52:01+00:00Added an answer on June 17, 2026 at 11:52 am

    if there are multiple instances, then process.start was called more then once. I would recommend that you write out logs and trace why your process.start is being called multiple times

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

Sidebar

Related Questions

I'm trying to create a simple script in batch to run in Windows, the
I created an application in Excel VBA that needs to run a batch file
My application creates photo and then inserts it into stock camera's bucket of gallery.
I have a DOS batch script that invokes a java application which interacts with
I am developing an application that needs to perform lots of batch processing (for
I have this batch file: @echo off echo StrText=Application created Successfully > spk.vbs echo
Is there a simple way to run a Python script on Windows/Linux/OS X? On
I'm a Silverlight/ASP.NET developer trying to write my first Windows Forms application to run
Currently I am starting my Slick 2D application via this batch file- java -Djava.library.path=lib
I'm writing an application in VB.net that creates and calls batch files. I'd like

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.