windows – 递归搜索HKU注册表配置单元的DWORD值
发布时间:2020-12-14 05:25:37 所属栏目:Windows 来源:网络整理
导读:我需要一个VBScript的帮助,它将以递归方式在 Windows HKU注册表配置单元中搜索DWORD值.如果脚本可以忽略仅查看S-1-5-21 *键的系统帐户,将会很有帮助.我必须使用HKU配置单元而不是HKCU配置单元来完成此操作,因为我计划用于运行脚本的程序在系统环境中运行.没
我需要一个VBScript的帮助,它将以递归方式在
Windows HKU注册表配置单元中搜索DWORD值.如果脚本可以忽略仅查看S-1-5-21 *键的系统帐户,将会很有帮助.我必须使用HKU配置单元而不是HKCU配置单元来完成此操作,因为我计划用于运行脚本的程序在系统环境中运行.没办法解决这个问题.
谢谢. Const HKCU = &H80000001 Const HKLM = &H80000002 Const HKU = &H80000003 strComputer = "." Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!" & _ strComputer & "rootdefault:StdRegProv") 'Read the HKEY_CURRENT_USER hive,registry path,and valuename to retrieve settings strKeyPath = "SoftwarePoliciesMicrosoftWindowsSystemPower" 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. ","=",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 & "rootdefault:StdRegProv") 'Enumerate All subkeys in HKEY_USERS objRegistry.EnumKey HKEY_USERS,"",arrSubkeys 'Define variables strKeyPath = "SoftwareMicrosoftWindowsCurrentVersionPoliciesAttachments" 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,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 解决方法
你这里不需要递归.只需遍历HKEY_USERS的子键并(尝试)读取该值. GetDWORDValue()的返回码将指示是否可以读取该值.
Const HKEY_USERS = &h80000003 subkey = "SoftwarePoliciesMicrosoftWindowsSystemPower" 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows – 通过Commandline / Powershell提取GPO
- Visual Studio太愚蠢,愚蠢了这么多年微软毫无知觉
- 在Windows XP上使用的端口
- 运行Windows程序并检测它何时以C结尾
- windows-server-2008 – Windows Web Server 2008 R2 Max R
- Windows Phone 8 – Windows Phone 8支持短信或来电?
- windows – Delphi:如何响应WM_SettingChange / WM_WinIni
- win10家庭版怎么开启Administrator超级管理员帐户
- active-directory – Windows AD和Linux LDAP服务器之间的统
- ntfs – 为什么ext3删除大文件这么慢?