How to Start/Stop a Windows Service from an ASP.NET app - Security issues -
- There is my Windows / Net Security Stack here:
- On a Windows service the local system Running as a Windows Server 2003 box.
- A .NET 3.5 website is running on the same box, under the "default" production server (maybe as a NETWORKSERVICE user?) IIS setting
Private Static Zero StopStartReminderService () {ServiceController svcController = New ServiceController (>: On my default VS2008 dev environment I have this method, which is the ASP.NET application, which works fine Called "eTimeSheetReminderService"); If (svcController! = Null) {try {svcController.Stop ()} SvcController.WaitForStatus (ServiceControllerStatus.Stopped, TimeSpenFormsCoins (10)); SvcController.Start (); } Hold (exception before) {normal. Error. }}}When I run this on the production server, I get the following error from ServiceController:
Source: System.ServiceProcess -> System .ServiceProcess.ServiceController -> IntPtr GetServiceHandle (Int32) -> System.InvalidOperationException Message: '.'. Can not open eTimeSheetReminderService service on the computer
Why is it happening, and how can I fix this?
Edit:
The answer is below, in most comments, but to clarify:
- The issue was related to security, and happened because the NETWORKSERVICE account did not have sufficient authority to start / stop a service
- I created a local user account and added it in the PowerUsers group (around this group Admin rights are)
- I do not want my entire web app to be that user To impersonate every time, I impersonate the method where I manipulate the service. I use the following resources to help me do this in the code:
and
Note: I through this Web.config does not impersonate, I'll do it in code above to view MS KB article.
Try adding it to your web. Confief
& lt; Identification impersonation = "true" />
Comments
Post a Comment