• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 703
  • Last Modified:

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
0
orenisraeli2000
Asked:
orenisraeli2000
1 Solution
 
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
 
Todd GerbertIT 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
 
Anurag ThakurCommented:
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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Tackle projects and never again get stuck behind a technical roadblock.
Join Now