若安装了 如何判断SQL Server 服务管理器是否已经启动? 你可以使用Microsoft SQLDMO Object Library 判断,我没有试过或者 你可以用下面这种办法使用WMI来得到系统的服务 WMI是可伸缩的系统管理结构,该规范采用一个统一、基于标准且可扩展的面向对象接口。它提供与系统管理员信息和基础WMI API交互的标准方法,主要由系统管理应用程序开发人员和系统管理员用来访问和操作系统管理信息。 WMI可用来生成组织和管理系统信息的工具,使系统管理人员能够更密切的监视系统活动。 WMI提供了一套内置在Microsoft Windows操作系统中的丰富的系统管理服务,现在有大量的应用程序、服务和设备用其为信息技术操作和产品支持组织提供全方位的管理功能。基于WMI的管理系统的使用带来了更可靠的计算环境和更高的系统可靠性。 我们看看怎样通过WMI提供的强大功能来实现windows系统服务的浏览、启动和关闭。Winxp+VB6+SP6 新建VB工程,在form上添加ListView,3个按钮控件。 '引用microsoft wmi scripting v1.2 library代码如下: Public Locator As SWbemLocator Public services As SWbemServices 'Dim oWMINameSpace As SWbemServices'引用microsoft wmi scripting v1.2 library Private Sub Form_Load() 'Set oWMINameSpace = GetObject("winmgmts:") ListView1.ListItems.Clear ListView1.ColumnHeaders.Add , , "服务名", 1000 ListView1.ColumnHeaders.Add , , "详细信息", 4000 ListView1.ColumnHeaders.Add , , "状态", 1000
'实例化 Set Locator = New SWbemLocator '连接计算机,”yang”是计算机名 Set services = Locator.ConnectServer("yang") End SubPrivate Sub Command1_Click() Dim Item As ListItem Set ServiceSet = GetObject("winmgmts:").InstancesOf("Win32_Service")For Each Service In ServiceSet Set Item = ListView1.ListItems.Add(, Service.Name, Service.Name) Item.SubItems(1) = Service.Description & "" Item.SubItems(2) = Service.State & "" Next End SubPrivate Sub Command2_Click() Dim ServiceObject As SWbemObject Dim ServiceName
On Error Resume Next ServiceName = ListView1.SelectedItem.Text If Err.Number = 0 Then Set ServiceObject = services.Get("Win32_Service='" & ServiceName & "'") ServiceObject.StartService End If End SubPrivate Sub Command3_Click() Dim ServiceObject As SWbemObject Dim ServiceName
On Error Resume Next ServiceName = ListView1.SelectedItem.Text If Err.Number = 0 Then
Set ServiceObject = services.Get("Win32_Service='" & ServiceName & "'") ServiceObject.StopService End If End Sub运行后,点击按钮,ListView中就出现了系统的服务,然后可以选择任意一项,选择启动或者关闭操作。
你可以使用Microsoft SQLDMO Object Library 判断,我没有试过或者
你可以用下面这种办法使用WMI来得到系统的服务
WMI是可伸缩的系统管理结构,该规范采用一个统一、基于标准且可扩展的面向对象接口。它提供与系统管理员信息和基础WMI API交互的标准方法,主要由系统管理应用程序开发人员和系统管理员用来访问和操作系统管理信息。
WMI可用来生成组织和管理系统信息的工具,使系统管理人员能够更密切的监视系统活动。
WMI提供了一套内置在Microsoft Windows操作系统中的丰富的系统管理服务,现在有大量的应用程序、服务和设备用其为信息技术操作和产品支持组织提供全方位的管理功能。基于WMI的管理系统的使用带来了更可靠的计算环境和更高的系统可靠性。
我们看看怎样通过WMI提供的强大功能来实现windows系统服务的浏览、启动和关闭。Winxp+VB6+SP6
新建VB工程,在form上添加ListView,3个按钮控件。
'引用microsoft wmi scripting v1.2 library代码如下:
Public Locator As SWbemLocator
Public services As SWbemServices
'Dim oWMINameSpace As SWbemServices'引用microsoft wmi scripting v1.2 library
Private Sub Form_Load()
'Set oWMINameSpace = GetObject("winmgmts:")
ListView1.ListItems.Clear
ListView1.ColumnHeaders.Add , , "服务名", 1000
ListView1.ColumnHeaders.Add , , "详细信息", 4000
ListView1.ColumnHeaders.Add , , "状态", 1000
'实例化
Set Locator = New SWbemLocator
'连接计算机,”yang”是计算机名
Set services = Locator.ConnectServer("yang")
End SubPrivate Sub Command1_Click()
Dim Item As ListItem
Set ServiceSet = GetObject("winmgmts:").InstancesOf("Win32_Service")For Each Service In ServiceSet
Set Item = ListView1.ListItems.Add(, Service.Name, Service.Name)
Item.SubItems(1) = Service.Description & ""
Item.SubItems(2) = Service.State & ""
Next
End SubPrivate Sub Command2_Click()
Dim ServiceObject As SWbemObject
Dim ServiceName
On Error Resume Next
ServiceName = ListView1.SelectedItem.Text
If Err.Number = 0 Then
Set ServiceObject = services.Get("Win32_Service='" & ServiceName & "'")
ServiceObject.StartService
End If
End SubPrivate Sub Command3_Click()
Dim ServiceObject As SWbemObject
Dim ServiceName
On Error Resume Next
ServiceName = ListView1.SelectedItem.Text
If Err.Number = 0 Then
Set ServiceObject = services.Get("Win32_Service='" & ServiceName & "'")
ServiceObject.StopService
End If
End Sub运行后,点击按钮,ListView中就出现了系统的服务,然后可以选择任意一项,选择启动或者关闭操作。