如何在 C# 中使用 net stop 命令启动/停止服务
如何在 C# 中使用 net stop 命令启动/停止服务 例如
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()
我使用了进程类但没有结果
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 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.
您可能想查看 System.ServiceProcess.ServiceController< /a> 类,它提供 Windows 服务的托管接口。
在这种情况下:
You might want to take a look at the System.ServiceProcess.ServiceController class, which provides a managed interface to Windows' Services.
In this case:
您需要将“/c”开关传递给cmd.exe
You need to pass the "/c" switch to cmd.exe