如何在c#中使用net stop命令启动/停止服务 [英] how do start/stop services using net stop command in c#
本文介绍了如何在c#中使用net stop命令启动/停止服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在c#中使用net stop命令启动/停止服务例如
how do start/stop services using net stop command in c# for example
Dim pstart As New ProcessStartInfo
Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.System)
Dim p As New Process
pstart.FileName = path + "cmd.exe"
pstart.UseShellExecute = False
pstart.CreateNoWindow = True
pstart.WorkingDirectory = path
pstart.FileName = "cmd.exe"
pstart.Arguments = " net start mysql"
p.StartInfo = pstart
p.Start()
我使用过进程类但没有结果
i have used process class but no result
推荐答案
您可以使用 ServiceController 类来启动/停止本地/远程机器上的特定服务.
Instead of using a crude method like Process.Start, you can use the ServiceController class to start/stop a particular service on a local/remote machine.
using System.ServiceProcess;
ServiceController controller = new ServiceController();
controller.MachineName = ".";
controller.ServiceName = "mysql";
// Start the service
controller.Start();
// Stop the service
controller.Stop();
这篇关于如何在c#中使用net stop命令启动/停止服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文