如何使用vb.net从网页启动和停止服务 [英] How to start and stop service from web page using vb.net
本文介绍了如何使用vb.net从网页启动和停止服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在vb.net中启动和停止服务表单网页,我有一个windows exe并安装在机器上,它启动它的服务,可以从控制面板看到服务。我想验证服务是否正在运行如果正在运行,我想停在一个按钮,在另一个按钮,如果服务停止它启动,请回复as /
thanx
how to start and stop service form web page in vb.net,i have a windows exe and install in machine ,it start its service and can see in service from control panel.i want to verify that service is running or not.if running i want to stop in one button ,in another button if service is stop it start,pls reply asap
thanx
推荐答案
Imports System.ServiceProcess
Public Sub StopService(ByVal myServiceName As String)
Dim DataSource As String = txtServer.Text
Dim sStatus As String
Dim myController As ServiceController
myController = New ServiceController
myController.MachineName = DataSource
myController.ServiceName = myServiceName
TextBox1.Text += "Stopping service """ & myServiceName & """...." & vbNewLine
If myController.Status = ServiceProcess.ServiceControllerStatus.Stopped Then
TextBox1.Text += "Service """ & myServiceName & """ is already stopped" & vbNewLine
Else
Try
myController.Refresh()
sStatus = myController.Status.ToString
myController.Stop()
myController.WaitForStatus(ServiceControllerStatus.Stopped)
TextBox1.Text += "Service """ & myServiceName & """ stopped..." & vbNewLine
Catch exp As Exception
TextBox1.Text += "Could not stop service """ & myServiceName & """" & vbNewLine
End Try
End If
End Sub
Public Sub StartService(ByVal myServiceName As String)
Dim DataSource As String = txtServer.Text
Dim sStatus As String
Dim myController As ServiceController
myController = New ServiceController
myController.MachineName = DataSource
myController.ServiceName = myServiceName
TextBox1.Text += "Starting service """ & myServiceName & """...." & vbNewLine
Try
myController.Refresh()
sStatus = myController.Status.ToString
myController.Start()
myController.WaitForStatus(ServiceControllerStatus.Running)
TextBox1.Text += "Service """ & myServiceName & """ started..." & vbNewLine
Catch exp As Exception
TextBox1.Text += "Could not start service """ & myServiceName & """" & vbNewLine
End Try
End Sub
这篇关于如何使用vb.net从网页启动和停止服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文