Wednesday, 15 January 2014

run windows service from asp.net web page -


I have a web page written in vb, I need to start a Windows service that is installed on the server Will be done.

A reference to the service process assembly must be added. The following code is almost what you want to do (I am using a label control named messageLabel in the following):

  using the system; Using System.Collections.Generic; Using System.Linq; Using System.ServiceProcess; Using System.Web; Using System.Web.UI; Using System.Web.UI.WebControls; Public Partial Class StartService: System.Web.UI.Page {Secure Zero Page_load (Object Sender, EventArgs e) {string serviceName = "Remote Registry"; Try {StartServiceByName (serviceName); } Hold (exception before) {messageLabel.Text = ex.ToString (). Change ("\ r \ n", "& lt; BR & gt;"); Return; } MessageLabel.Text = String.Format ("Service started {0}.", ServiceName); } Private Zero StartServiceByName (string savannum) {ServiceController serviceController = New ServiceController (serviceName); ServiceController.Start (); However, there is one more thing - you need to allow the web server to change this service - which can normally be done only with the authority of the administration. 


No comments:

Post a Comment