简体   繁体   中英

How to Start multiple windows Services from asp.net web application?

I want to restart a set of windows services which are running on my local computer. I want to restart all these services at once when i click a button in my asp.net application ?

I would appreciate if any one can help me out .

As of now i am able to implement the scenario for restarting a single windows service by using Service Controller Class.

Just put a loop in iterating through each service name. Create a ServiceController for each service name and restart it there.

List<string> serviceList = //however you get all of the services you want to start, put them in here.

foreach(string serviceName in serviceList)
{
   ServiceController controller = new ServiceController(serviceName);
   ....

   controller.Restart();
}

To use a batch file use:

 System.Diagnostics.Process.Start(pathToBatchFile); 

You can manage the process by using intellisense and a little curiosity. Also, here is an msdn article I found for you.

http://blogs.msdn.com/b/csharpfaq/archive/2004/06/01/146375.aspx

To hide the command prompt and have more control over the process, use the System.Diagnostics.ProcessStartInfo class and pass its object to the Process.Start method. You can even catch the output from the batch file inside your program.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM