Unable to Enumerate and Delete Registry Values Using VBScript

293 views Asked by At

I need to iterate through the registry foe each application for which the following key exists:

HKCU\Software\Microsoft\Office\15.0\[NAME OF APPLICATION]\Resiliency\DisabledItems

So that I can delete any values stored here.

I wrote the below script, but all this seems to do is iterate through the keys until it reaches Outlook, at which point it assures me the key does not exist (even though it definitely does), and then the script stops running.

'***********************************************'
'------------------------------------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

Some background: The script seems to work perfectly when I run it on my dev machine. It enumerates all keys and all values and deletes the ones which I need deleting. However, when I run this from a thin client (which is where the script will be deployed - in a log on script), I am seeing the behaviour described above.

When I load the registry hive from the test user (who is logged into the thin client), I can see that there are many more keys in addition to those being checked, but for some reason it stops checking after Outlook.

Am I missing some sort of error, or am I misunderstanding how the registry works?

1

There are 1 answers

0
Bassie On BEST ANSWER

This was due to the way our Citrix and Windows environment is set up.

The logon script is called from the server via Active Directory User -> Properties -> Profile

The script above where I was having the issue was executing locally on the machine, and so none of the application's registry keys were present, as these applications are installed on the server.

After adding my code to the server-hosted logon script, it was able to detect and delete all the required key values.