r.r
r.r

Reputation: 7153

how to turn windows service on if its off. control it from webapplication

i want to turn windows service on when it is off. is it possible to make via code from web application with c#? i am using asp.net mvc and c#.

Upvotes: 5

Views: 2634

Answers (4)

Felice Pollano
Felice Pollano

Reputation: 33252

Here an example:

                var sc = new ServiceController("Your service name");
                sc.Stop();
                sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(120));
                logger.Info("service stopped.");

Upvotes: 2

SecretDeveloper
SecretDeveloper

Reputation: 3140

Its possible to do it but its unlikely that you want to run your website under an account which has enough rights to be able to Start/Stop services. You can use the ServiceController class to start a service see here

Upvotes: 6

CheeZe5
CheeZe5

Reputation: 995

Use the ServiceController class.

Upvotes: 1

SLaks
SLaks

Reputation: 887453

You're looking for the ServiceController class.

Upvotes: 7

Related Questions