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?
Create the Windows Service, Open Visual Studio, from the File Menu, select New and then choose Project. It will open a New Project window where you can choose various type of the project. Go to Visual C# and select Classic Desktop and from the next window, choose Windows Service.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With