Link to home
Start Free TrialLog in
Avatar of orenisraeli2000
orenisraeli2000

asked on

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
Avatar of talker2004
talker2004
Flag of United States of America image

   // 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) {
    }
}
ASKER CERTIFIED SOLUTION
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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"
Avatar of orenisraeli2000
orenisraeli2000

ASKER

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.
Correction, all is good.
I loved this fancy pants solution.
nice1

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.