发现要使用WMI,不一定要引用microsoft wmi scripting
如下:找出安装的sql Server服务
Dim objServer As Object
Dim objSet As Object
Dim obj As Object
Dim strComputer As String,strServiceName As String
Dim idx As Integer
ReDim g_strsqlServer(32)
strComputer = "."
idx = 0
Set objServer = GetObject("Winmgmts://" &strComputer)
Set objSet = objServer.InstancesOf("Win32_Service")
For Each obj In objSet
strServiceName = UCase(obj.Name)
If InStr(strServiceName,"MSsql") > 0 then
g_strsqlServer(idx) = obj.Name
idx = idx + 1
End If
Next
此代码在window2000,VB6,sqlServer2000下通过
甚至于:
GetOjbect可以换成CreateObject
上一次所 讲的几种方法都可以使用。
唯一的区别就是,
不能定义如WbemScripting.SwbemObject,全要换成object
原文链接:https://www.f2er.com/vb/259502.html