stop命令停止服务

stop命令停止服务

本文介绍了如何启动/在C#中使用net stop命令停止服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何开始/在C#
例如:

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

推荐答案

而不是使用像的Process.Start原油方法,你可以使用的以班级开始/停止特定的服务。

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命令停止服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 17:33