Reputation: 349
I tried System.ServiceProcess.ServiceController System.Diagnostics.Process;
to control windows services in my web form.
With System.ServiceProcess.ServiceController
I am getting Access Denied Exception.
With System.Diagnostics.Process
I get nothing. How can I start/stop Windows Services with my web form, any idea?
Upvotes: 7
Views: 6536
Reputation: 7693
Here are the important points to accomplish:
1 You need to add System.ServiceProcess reference in your application. This namespace holds ServiceController Class to access the window service.
2 You need to check the status of the window services before you explicitly start or stop it.
3 By default, IIS application runs under ASP.NET account which doesn't have access rights permission to window service. So, Very Important part of the solution is: Impersonation. You need to impersonate the application/part of the code with the User Credentials which is having proper rights and permission to access the window service.
Refer this blog entry from asp.net And also look at this https://stackoverflow.com/a/17497084/1641556
Upvotes: 6
Reputation: 91
Knelis is correct, I think you just need another process to do that. Maybe your own windows service, which run under local system, and provide a wcf service to control windows service, and your web app can call the wcf service.
Upvotes: 2