4

HKUWindowsレジストリ ハイブでDWORD値を再帰的に検索する VBScript について助けが必要です。S-1-5-21*スクリプトがキーのみを調べるシステム アカウントを無視できると便利です。スクリプトを実行するために使用する予定のプログラムはシステムのコンテキストで実行されるため、HKUハイブではなくハイブを使用してこれを達成する必要があります。HKCUそれを回避する方法はありません。

ありがとうございました。

Const HKCU = &H80000001  
Const HKLM = &H80000002  
Const HKU =  &H80000003  

strComputer = "."

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

'Read the HKEY_CURRENT_USER hive, registry path, and valuename to retrieve settings
strKeyPath = "Software\Policies\Microsoft\Windows\System\Power"
strValueName = "PromptPasswordOnResume"
oReg.GetDWORDValue HKCU,strKeyPath,strValueName,dwValue

'Return a failure exit code if entry does not exist
If IsNull(dwValue) Then
   Wscript.Echo "The value is either Null or could not be found in the registry."
   WScript.Quit 1

'Return a failure exit code if value does not equal STIG setting    
ElseIf dwValue <> 1 Then
   Wscript.Echo "This is a finding. ", strValueName,"=", dwValue
   WScript.Quit 1

'Return a passing exit code if value matches STIG setting   
ElseIf dwValue = 1 Then
   Wscript.Echo "This is not a finding. "
   WScript.Quit 0

End If

これはすべて、私の問題を解決するために最終的に思いついたものです。

Const HKEY_CURRENT_USER = &H80000001  
Const HKEY_LOCAL_MACHINE = &H80000002  
Const HKEY_USERS = &H80000003  

'Set the local computer as the target

strComputer = "."

'set the objRegistry Object 
Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

'Enumerate All subkeys in HKEY_USERS
objRegistry.EnumKey HKEY_USERS, "", arrSubkeys

'Define variables
strKeyPath = "\Software\Microsoft\Windows\CurrentVersion\Policies\Attachments"  
strValueName = "HideZoneInfoOnProperties"  
strSID = "S-1-5-21-\d*-\d*-\d*-\d{4,5}\\"  
strValue = 1  

f = True

For Each i in arrSubKeys
    Set objRegExp = New RegExp
        objRegExp.IgnoreCase = True
        objRegExp.Global = True
        objRegExp.Pattern = strSID

    Set colMatches = objRegExp.Execute(i + strKeyPath)  
        For Each objMatch In colMatches
        objRegistry.GetDWORDValue HKEY_USERS,i + strKeyPath,strValueName,dwValue

            If IsNull(dwValue) Then
                WScript.Echo "This is a finding, the key " & i + strKeyPath & "\" & strValueName & " does not exist."
                f = False
            ElseIf dwValue <> strValue Then
                WScript.Echo "This is a finding, the " & i + strKeyPath & "\" & strValueName & ": " & dwValue & " does not equal REG_DWORD = " & strValue & "."
                f = False
            ElseIf dwValue = strValue Then
                WScript.Echo "This is not a finding " & i + strKeyPath & "\" & strValueName & " = " & dwValue
            End If
        Next


Next

    If f Then
        WScript.Quit 0
    Else
        WScript.Quit 1
    End If
4

2 に答える 2

3

ここでは再帰は必要ありません。HKEY_USERS のサブキーを繰り返し処理し、(試行して) 値を読み取るだけです。willの戻りコードはGetDWORDValue()、値が読み取れたかどうかを示します。

Const HKEY_USERS = &h80000003

subkey = "Software\Policies\Microsoft\Windows\System\Power"
name   = "PromptPasswordOnResume"

computer = "."

Set reg = GetObject("winmgmts://" & computer & "/root/default:StdRegProv")

reg.EnumKey HKEY_USERS, "", sidList
For Each sid In sidList
  key = sid & "\" & subkey
  rc = reg.GetDWORDValue(HKEY_USERS, key, name, val)
  If rc = 0 Then
    If val = 1 Then
      WScript.Echo "OK"
      WScript.Quit 0
    Else
      WScript.Echo "Not OK"
      WScript.Quit 1
    End If
  End If
Next
于 2012-11-04T13:04:57.033 に答える
0

私があなたを正しくしたかどうかはわかりません。HKCUではなくHKUで検索する場合は、HKUのアカウントがHKCUにマップされていることが重要です。あなたの場合のように、S-1-5-21*はHKCUにマッピングされます。HKCUのエントリを変更することで確認でき、HKU(S-1-5-21 *)に反映されます。その逆も同様です。

于 2012-11-04T09:09:09.390 に答える