无法使用 VBScript 枚举和删除注册表值
Unable to Enumerate and Delete Registry Values Using VBScript
我需要遍历存在以下键的每个应用程序的注册表:
HKCU\Software\Microsoft\Office.0\
[申请名称]\Resiliency\DisabledItems
这样我就可以删除存储在此处的任何值。
我写了下面的脚本,但这似乎只是遍历键直到它到达 Outlook
,此时它向我保证键不存在(即使它确实存在),然后脚本停止 运行ning.
'***********************************************'
'------------------------------------Add-In Keys'
'***********************************************'
Sub AddInKeys()
On Error Resume Next
strOfficePath = "Software\Microsoft\Office.0\"
objReg.EnumKey conHKEY_CURRENT_USER, strOfficePath, arrOfficeSubKeys
for Each key in arrOfficeSubKeys
' Check if our DisabledItems key exists
If regExists("HKCU\Software\Microsoft\Office.0\" & key & "\Resiliency\DisabledItems\") Then
' If it does - enumerate the values under this key ...
objReg.EnumValues conHKEY_CURRENT_USER, strOfficePath & key & "\Resiliency\DisabledItems\", arrKeyValues
For Each value in arrKeyValues
' Delete key VALUE, but only IF it is not blank (this will be the default value)
If value <> "" Then
objShell.RegDelete "HKCU\Software\Microsoft\Office.0\" & key & "\Resiliency\DisabledItems\" & value
End If
Next
End If
Next
If Err <> 0 Then
strMessage = "ERROR: Sub - Add-In Keys"
End If
End Sub
'***********************************************'
'---Function to check existence of registry keys'
'***********************************************'
Function regExists(sKey)
ON ERROR RESUME NEXT
regExists = objShell.RegRead(sKey)
If Err.Number = 0 Then
regExists = True
Else
regExists = False
Err.Number = 0
End If
If Err <> 0 Then
strMessage = "ERROR: Sub - regExists"
End If
End Function
一些背景:当我在我的开发机器上 运行 时,脚本似乎运行良好。它枚举所有键和所有值并删除我需要删除的键和值。但是,当我 运行 从瘦客户端(即部署脚本的位置 - 在登录脚本中)执行此操作时,我看到了上述行为。
当我从测试用户(登录到瘦客户端)加载注册表配置单元时,我可以看到除了被检查的那些之外还有更多的键,但由于某种原因它在 Outlook 之后停止检查.
我是否遗漏了某种错误,或者我误解了注册表的工作原理?
这是由于我们的 Citrix 和 Windows 环境的设置方式所致。
通过 Active Directory 从服务器调用登录脚本 User -> Properties -> Profile
上面我遇到问题的脚本是在机器上本地执行的,因此存在 none 个应用程序的注册表项,因为这些应用程序安装在服务器上。
将我的代码添加到服务器托管的登录脚本后,它能够检测并删除所有必需的键值。
我需要遍历存在以下键的每个应用程序的注册表:
HKCU\Software\Microsoft\Office.0\
[申请名称]\Resiliency\DisabledItems
这样我就可以删除存储在此处的任何值。
我写了下面的脚本,但这似乎只是遍历键直到它到达 Outlook
,此时它向我保证键不存在(即使它确实存在),然后脚本停止 运行ning.
'***********************************************'
'------------------------------------Add-In Keys'
'***********************************************'
Sub AddInKeys()
On Error Resume Next
strOfficePath = "Software\Microsoft\Office.0\"
objReg.EnumKey conHKEY_CURRENT_USER, strOfficePath, arrOfficeSubKeys
for Each key in arrOfficeSubKeys
' Check if our DisabledItems key exists
If regExists("HKCU\Software\Microsoft\Office.0\" & key & "\Resiliency\DisabledItems\") Then
' If it does - enumerate the values under this key ...
objReg.EnumValues conHKEY_CURRENT_USER, strOfficePath & key & "\Resiliency\DisabledItems\", arrKeyValues
For Each value in arrKeyValues
' Delete key VALUE, but only IF it is not blank (this will be the default value)
If value <> "" Then
objShell.RegDelete "HKCU\Software\Microsoft\Office.0\" & key & "\Resiliency\DisabledItems\" & value
End If
Next
End If
Next
If Err <> 0 Then
strMessage = "ERROR: Sub - Add-In Keys"
End If
End Sub
'***********************************************'
'---Function to check existence of registry keys'
'***********************************************'
Function regExists(sKey)
ON ERROR RESUME NEXT
regExists = objShell.RegRead(sKey)
If Err.Number = 0 Then
regExists = True
Else
regExists = False
Err.Number = 0
End If
If Err <> 0 Then
strMessage = "ERROR: Sub - regExists"
End If
End Function
一些背景:当我在我的开发机器上 运行 时,脚本似乎运行良好。它枚举所有键和所有值并删除我需要删除的键和值。但是,当我 运行 从瘦客户端(即部署脚本的位置 - 在登录脚本中)执行此操作时,我看到了上述行为。
当我从测试用户(登录到瘦客户端)加载注册表配置单元时,我可以看到除了被检查的那些之外还有更多的键,但由于某种原因它在 Outlook 之后停止检查.
我是否遗漏了某种错误,或者我误解了注册表的工作原理?
这是由于我们的 Citrix 和 Windows 环境的设置方式所致。
通过 Active Directory 从服务器调用登录脚本 User -> Properties -> Profile
上面我遇到问题的脚本是在机器上本地执行的,因此存在 none 个应用程序的注册表项,因为这些应用程序安装在服务器上。
将我的代码添加到服务器托管的登录脚本后,它能够检测并删除所有必需的键值。