VBS实现查询服务的制造商
一个网友提问:
select*fromwin32_service这个能查服务名称、状态……
但我想查这个服务的制造商,如微软、农业银行,还是未知的??这个属性是什么,谢谢……
我发现msconfig中可以看见的,但无法提取
下面给出解答,一种间接方法:
根据服务名获取到关联的主程序,再从主程序获取制造商
SetobjWMIService=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
SetServices=objWMIService.ExecQuery("Select*fromWin32_Service")
Setfso=CreateObject("Scripting.FileSystemObject")
SetobjShell=CreateObject("Shell.Application")
SetobjFolder=objShell.NameSpace(0)
i=0
Do
IfobjFolder.GetDetailsOf("",i)="公司"Then'非中文系统自行修改
ExitDo
Else
i=i+1
EndIf
Loop
ForEachobjServiceinServices
path=GetPath(objService.PathName)
IFfso.GetExtensionName(path)=""Thenpath=path&".exe"
SetobjFolder=objShell.NameSpace(fso.GetParentFolderName(path))
SetobjItem=objFolder.ParseName(fso.GetFileName(path))
comp=objFolder.GetDetailsOf(objItem,i)
Ifcomp=""Thencomp="未知"
info=info&"服务:"&objService.DisplayName&"制造商:"&comp&vbCrLF
Next
fso.CreateTextFile("info.txt",true).WriteLineinfo
MsgBox"完成"
FunctionGetPath(strng)
Dimre
Setre=NewRegExp
re.Pattern="^""?(.+\\[^\\\s""]+).*"
GetPath=re.Replace(strng,"$1")
SetregEx=Nothing
EndFunction
是不是非常不错的解法,小伙伴们可以学习下。