0

我需要遍历存在以下键的每个应用程序的注册表:

HKCU\Software\Microsoft\Office\15.0\[申请名称]\Resiliency\DisabledItems

这样我就可以删除此处存储的任何值。

我编写了下面的脚本,但这似乎只是遍历键直到它到达Outlook,此时它向我保证键不存在(即使它确实存在),然后脚本停止运行。

'***********************************************'
'------------------------------------Add-In Keys'
'***********************************************'
Sub AddInKeys()
    On Error Resume Next

    strOfficePath = "Software\Microsoft\Office\15.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\15.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\15.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 之后停止检查。

我错过了某种错误,还是我误解了注册表的工作原理?

4

1 回答 1

0

这是由于我们的 Citrix 和 Windows 环境的设置方式。

通过 Active Directory 从服务器调用登录脚本User -> Properties -> Profile

上面我遇到问题的脚本是在机器上本地执行的,因此应用程序的注册表项都不存在,因为这些应用程序安装在服务器上。

将我的代码添加到服务器托管的登录脚本后,它能够检测并删除所有必需的键值。

于 2016-02-17T16:34:20.163 回答