(编辑:jimmy 日期: 2024/12/24 浏览:2)
一个网友提问:
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
是不是非常不错的解法,小伙伴们可以学习下。