Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:




I can control my computer services. ( Local )

I'm publishing on a server. I can see the status of services. But, I can not change the service status.

How do I make a change in state. Thanks!
Posted

First of all, I suggest you never try to start and stop your service. This is done by a service controller, but you could not get permission for controlling it for your Web application. Normally, Web applications are executed in the sandboxed environment and are well isolated from any activity which could compromise system behavior; and this is done on top of "regular" system permissions. There are many other reasons to avoid it.

Instead, your service should work all the time. Instead of "stopping" and "starting", you have to have different modes in service activity on the application level: in one mode it operates normally, in other mode, it is working, but its application activity is suspended, its functionality can be reduced to accepting the connection from the administrative client and the commands from this client, so one of the commands could resume the operation of the service.

I mentioned administrative client above. Your service should include some, say, network service, used by what I called "administrative client". This client should connect to the service and send commands like those I described above. Some part of your code behind should implement such a client. In turn, this client should send its commands in response to the user action on some ASP.NET Web page, from the user properly authenticated, and so one, and so forth…

—SA
 
Share this answer
 
Comments
DamithSL 5-May-14 10:55am    
great answer Alex 5+
Sergey Alexandrovich Kryukov 5-May-14 11:06am    
Thank you very much, but none of my names have anything to do with "Alex".
—SA
DamithSL 5-May-14 11:09am    
Extremely sorry ;) next time I'll use your full name @Sergey Alexandrovich Kryukov
Sergey Alexandrovich Kryukov 5-May-14 11:20am    
Please, SA or Sergey, Sergey Alexandrovich (always without the family name) is the official polite Russian form.
—SA
this is most probably due to security issue, your asp.net application pool user may not have sufficient rights to Start/Stop a service.

first try to set application user as an administrator user. if that is working fine then you can impersonate user for this function only.(otherwise it will be more risky with running asp.net site with high previleges account)
Quote:
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.

Follow Start/Stop Window Service from ASP.NET page[^] blog post.
 
Share this answer
 
v3
I did a project with windows service in ASP.NET, and this is my summary for it, hope it helps you: http://codingfarmer.blogspot.com/2014/06/startstop-window-service-from-aspnet.html[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900