一个网友提问:

select * from win32_service 这个能查服务名称、状态……

但我想查这个服务的制造商,如微软、农业银行,还是未知的??这个属性是什么,谢谢……

我发现msconfig中可以看见的,但无法提取

下面给出解答,一种间接方法:

根据服务名获取到关联的主程序,再从主程序获取制造商

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set Services = objWMIService.ExecQuery("Select * from Win32_Service")
Set fso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(0)
i = 0
Do
  If objFolder.GetDetailsOf("", i) = "公司" Then '非中文系统自行修改
    Exit Do
  Else
    i = i+1
  End If
Loop

For Each objService in Services
  path = GetPath(objService.PathName)
  IF fso.GetExtensionName(path) = "" Then path = path & ".exe"
  Set objFolder = objShell.NameSpace(fso.GetParentFolderName(path))
  Set objItem = objFolder.ParseName(fso.GetFileName(path))
  comp = objFolder.GetDetailsOf(objItem, i)
  If comp = "" Then comp = "未知"
  info = info & "服务:"& objService.DisplayName &" 制造商:"& comp & vbCrLF
Next
fso.CreateTextFile("info.txt", true).WriteLine info
MsgBox "完成"

Function GetPath(strng)
  Dim re
  Set re = New RegExp
  re.Pattern = "^""""]+).*"
  GetPath = re.Replace(strng,"$1")
  Set regEx = Nothing
End Function

是不是非常不错的解法,小伙伴们可以学习下。

广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!