How to install a windows service and make hime run without reboot.

Hello,
I have a .Net App and a .Net windows service.
I'm using a Project Installer to install them on clients computer. How do I make the installed service to start running immediately without reboot. I don't want to do it manually using "My Compurt->Manage-> ...." I'm looking for a script or something.
Please give full solution. I'm using .Net 2
LVL 1
orenisraeli2000Asked:
Who is Participating?
 
Todd GerbertConnect With a Mentor IT ConsultantCommented:
You can use a VBScript or CMD script as a custom event in your setup project that runs "net start YourService"; or, if you want to be all fancy-pants, you can add .Net code to your setup project as a custom event that references System.ServiceController, then you can programatically control your service.


   using System.ServiceController;
 
   [RunInstaller(true)]
    public class MyCustomCommitEvent : Installer
    {
        public override void Commit(IDictionary savedState)
        {
            base.Commit(savedState);
            ServiceController myService = new ServiceController("YourService");
            myService.Start();
            
        }
    }

Open in new window

0
 
talker2004Commented:
   // Make sure the service name goes here.
    // you will need to make reference to system.serviceprocess
System.ServiceProcess.ServiceController ServiceController = new System.ServiceProcess.ServiceController("Service Name");

public void StartController()
{
    try {
        this.ServiceController.Refresh();
        if (this.ServiceController.Status != ServiceProcess.ServiceControllerStatus.Running) {
            ServiceController.Start();
        }
    }
    catch (Exception ex) {
    }
}
0
 
Anurag ThakurTechnical ManagerCommented:
you can create a bat file to start the service or stop the service using the net start and net stop commands

stopping the service
net stop "Service Name"

starting the service
net start "Service Name"
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
orenisraeli2000Author Commented:
talker2004: I dont understand where to put your code and how to invoke it.
tgerbert : Nice solution but Where to put the code?? I've put the code in the ProjectInstaller.cs file and nothing new happed.
0
 
orenisraeli2000Author Commented:
Correction, all is good.
I loved this fancy pants solution.
nice1

0
 
talker2004Commented:
when I seen tgerbert solution I knew his was going to beat mine out. Overriding the commit method was pretty slick to get it done during the install.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.