SoFunction
Updated on 2025-04-11

VBScript: Find hidden services by comparing the registry


'On Error Resume Next

Const HKEY_LOCAL_MACHINE = &H80000002

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

strKeyPath = "SYSTEM\CurrentControlSet\Services"
HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

"Checking, please wait ..."
""

For Each subkey In arrSubKeys
  HKEY_LOCAL_MACHINE, strKeyPath & "\\" & subkey, "ObjectName", strValue

 If Not (strValue = "") Then
'Judge the service, use arrays to compare and I don't know if it will be faster?
  If Not (CheckSvr(subkey)) Then
    subkey & FormatOutTab(subkey) & strValue & FormatOutTab(strValue) & "[ Hidden ]"
  Else 
    subkey & FormatOutTab(subkey) & strValue & FormatOutTab(strValue) & "[   OK   ]"
  End If

 End If
Next
""
"All done."
(0)

 

Function CheckSvr(strName)
 Set oWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
 Set cService = ("Select * from Win32_Service WHERE Name='" & strName & "'")
 If ( <> 0) Then
  CheckSvr = True
 Else
  CheckSvr = False
 End If
End Function

Function FormatOutTab(strName)
 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

  Case strLen < 32
   FormatOutTab =  vbTab & vbTab

  Case strLen < 40
   FormatOutTab =  vbTab

  Case Else
   FormatOutTab =  vbTab
  End Select
End Function