VBScript之通過(guò)對(duì)比注冊(cè)表查找隱藏的服務(wù)

代碼(checksvr.vbs):
Const HKEY_LOCAL_MACHINE = &H80000002 Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") strKeyPath = "SYSTEM\CurrentControlSet\Services" Wscript.Echo "Checking, please wait ..." For Each subkey In arrSubKeys End If Function CheckSvr(strName) Function FormatOutTab(strName) Case strLen < 32
'On Error Resume Next
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
Wscript.Echo ""
oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & "\\" & subkey, "ObjectName", strValue
If Not (strValue = "") Then
'判斷服務(wù), 利用數(shù)組來(lái)比較不知道會(huì)不會(huì)快些?
If Not (CheckSvr(subkey)) Then
Wscript.Echo subkey & FormatOutTab(subkey) & strValue & FormatOutTab(strValue) & "[ Hidden ]"
Else
Wscript.Echo subkey & FormatOutTab(subkey) & strValue & FormatOutTab(strValue) & "[ OK ]"
End If
Next
Wscript.Echo ""
Wscript.Echo "All done."
Wscript.Quit (0)
Set oWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set cService = oWMI.ExecQuery("Select * from Win32_Service WHERE Name='" & strName & "'")
If (cService.count <> 0) Then
CheckSvr = True
Else
CheckSvr = False
End If
End Function
strLen = Len(strName)
Select Case True
Case strLen < 8
FormatOutTab = vbTab & vbTab & vbTab & vbTab & vbTab
Case strLen < 16
FormatOutTab = vbTab & vbTab & vbTab & vbTab
Case strLen < 24
FormatOutTab = vbTab & vbTab & vbTab
FormatOutTab = vbTab & vbTab
Case strLen < 40
FormatOutTab = vbTab
Case Else
FormatOutTab = vbTab
End Select
End Function
利用字典,速度要快很多:
Wscript.Echo "[*] Checking, please wait ..." Set oDic = CreateObject("Scripting.Dictionary") Set oWmi = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2") Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") For Each subkey In arrSubKeys oDic.RemoveAll Wscript.Echo "" Case strLen < 32 Case Else
Dim oDic, oReg, oWmi, arrServices
Const HKEY_LOCAL_MACHINE = &H80000002
Wscript.Echo ""
Set arrServices = oWmi.ExecQuery("Select * from Win32_Service")
For Each strService In arrServices
oDic.Add strService.Name, strService.Name
Next
strKeyPath = "SYSTEM\CurrentControlSet\Services"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & "\\" & subkey, "ObjectName", strValue
If Not (strValue = "") Then
If oDic.Exists(subkey) Then
Wscript.Echo subkey & FormatOutTab(subkey) & strValue & FormatOutTab(strValue) & "[ OK ]"
Else
Wscript.Echo subkey & FormatOutTab(subkey) & strValue & FormatOutTab(strValue) & "[ Hidden ]"
End If
End If
Next
Wscript.Echo "[*] All done."
Wscript.Quit (0)
Function FormatOutTab(strName)
strLen = Len(strName)
Select Case True
Case strLen < 8
FormatOutTab = vbTab & vbTab & vbTab & vbTab
Case strLen < 16
FormatOutTab = vbTab & vbTab & vbTab
Case strLen < 24
FormatOutTab = vbTab & vbTab
FormatOutTab = vbTab
FormatOutTab = vbTab
End Select
End Function
來(lái)自: enun.net
相關(guān)文章
利用vbs腳本實(shí)現(xiàn)設(shè)置IE的打印頁(yè)眉頁(yè)腳信息
這篇文章主要為大家分享下通過(guò)vbs腳本實(shí)現(xiàn)設(shè)置IE的打印頁(yè)眉頁(yè)腳信息的代碼,需要的朋友可以參考下2007-02-02
VBS教程:VBscript語(yǔ)句-ExecuteGlobal 語(yǔ)句
VBS教程:VBscript語(yǔ)句-ExecuteGlobal 語(yǔ)句...2006-11-11
自己寫的一個(gè)定時(shí)關(guān)機(jī)或重啟的vbs腳本
'以下代碼是定時(shí)關(guān)機(jī)或重啟的腳本,在windows 2000下通過(guò)2008-06-06
vbs 查找硬盤分區(qū)中指定擴(kuò)展名文件的實(shí)現(xiàn)代碼
vbs 用于查找硬盤所有分區(qū)中指定擴(kuò)展名文件的代碼,有需要的朋友可以參考下。挺實(shí)用的一段代碼,用來(lái)深入學(xué)習(xí)vbs,確實(shí)不錯(cuò)2014-05-05
利用WSH里的MapNetworkDrive方法腳本蠕蟲(chóng)的傳播方式
利用WSH里的MapNetworkDrive方法腳本蠕蟲(chóng)的傳播方式...2007-02-02

