views:

137

answers:

3

i have a web page written in vb, i need to start a windows service that will be installed in the server.

A: 

haven't tested.

pleas try if works or not. you could add following code in btn click event.

dim controller as new ServiceController

controller.MachineName = "." //try the machine name
controller.ServiceName = "service name"
dim status as string = controller.Status.ToString

' Stop the service
controller.Stop()

' Start the service
controller.Start()
Saar
A: 

Depending on the permissions that the web site account has, you can start / stop services.

In addition to what others have answered, you can shell out NET START with the appropriate parameters.

You can also do this for remote computers as long as the permissions are granted (I think it has to be a domain account for this).

Raj More
A: 

You first need to add a reference to the System.ServiceProcess assembly. The following code gives you roughly what you want to do (I am using a Label control called messageLabel in the following):

using 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
{
    protected void Page_Load(object sender, EventArgs e)
    {
     string serviceName = "Remote Registry";
     try
     {
      StartServiceByName(serviceName);
     }
     catch (Exception ex)
     {
      messageLabel.Text = ex.ToString().Replace("\r\n", "<BR>");
      return;
     }
     messageLabel.Text = String.Format("Service {0} started.", serviceName);
    }

    private void StartServiceByName(string serviceName)
    {
     ServiceController serviceController = new ServiceController(serviceName);
     serviceController.Start();
    }
}

However, there is a further thing - you need to have the web server have permission to change this service - which is something that normally can be only done with Administration rights.

Mark Bertenshaw