• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1468
  • Last Modified:

Deleting HKEY_CURRENT_USER Subkey via HKEY_USERS

I need to delete a key from:
       HKEY_CURRENT_USER
             Software
                   MyCompany
for all users on the same machine

The documented procedure (internal) does not work. It says to delete:
       HKEY_USERS
              S-1-5-21-XXXXXX-XXXXXX-XXXX ...
                   Software
                           MyCompany

This only deletes the MyCompany key and its subkeys for the user currently logged on (Admin).

What is the correct way to do this?

Thank you.
trishm
0
trishm
Asked:
trishm
  • 4
  • 3
  • 3
  • +1
1 Solution
 
ghostdog74Commented:
one way is to use tools like scanreg (resource kit), regfind, (or reg ) to search for the word "MyCompany" and get a list of registry keys that are returned. Then using for loop to go over these keys and delete them
http://www.petri.co.il/download_free_reskit_tools.htm
0
 
jkrCommented:
That won't work unless the user in question is logged on. Only then the registry hive under HKCU will be loaded.
0
 
jkrCommented:
... and vice versa, if the user is not logged on, the key is not pesent and thus cannot be deleted.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ghostdog74Commented:
Since that's the case, it really doesn't matter, if the key is there, then it would be found. So delete it. If its not there, it won't be found and so be it.
0
 
jkrCommented:
Err, you cannot delete a key that is not present. And the purpose is to delete it, so it need s to be loaded first.
0
 
ghostdog74Commented:
I am still not clear by what you said. If the key is only loaded when a user logged in, that means its not a "permanent" key? If it's not permanent, and if a user is not logged in, the  key will not be there , right? So the registry tools that are used to query the key will not return anything. All we need to do in the batch is if it doesn't return the key found, we do nothing...pls correct me if i am wrong.
0
 
trishmAuthor Commented:
jkr:

Judging from what you've said, there is no way that the Admin user can delete another user's subkey in HKEY_CURRENT_USER. Is that correct?

If this is indeed the case, the only way to clear the registry of an item residing in HKEY_CURRENT_USER is to log on as each and every user and then delete it. Is this a fair assessment?
0
 
jkrCommented:
>>there is no way that the Admin user can delete another user's subkey in
>>HKEY_CURRENT_USER. Is that correct?

No, it *can* be done, it is just not that simple - if you are doing that by code, you should 'LogonUser()' for the user in question. Alternatively, you can map user's hive by calling 'RegLoadKey()' (http://msdn2.microsoft.com/en-us/library/ms724889.aspx). The latter however requires the Admin to be added to the "Backup Operators" group.
0
 
trishmAuthor Commented:
Clearing the registry is part of the software installation procedure I mentioned in my original question. Before installing a new release, the toolbar settings saved in HKCU need to be deleted.

Leaving an old toolbar state in the registry  "appears" to be wreaking havoc on the toolbar images after a new release is installed, but that is a whole 'nother question.
0
 
trishmAuthor Commented:
jkr:

Thank you for those code solutions. I will look into implementing them - perhaps as a separate "registry cleaner" app.

If I may ask one last question, I'd appreciate it.
Do you know if there is a way to do this outside of the code?
0
 
Gregg_dKCommented:
...Was looking for someting else and happened to have found a way around this recently that has been working so far, which works as local Administrator (should work as Backup Operator as well I believe); see code below.
'To remove something for ALL Users in HKEY_USERS:
    'Enumerate all "User" SIDs in HKU
        For User = 0 To (My.Computer.Registry.Users.SubKeyCount()) - 1
            UserSID = My.Computer.Registry.Users.GetSubKeyNames(User)

           'Remove what you want to (such as "SOFTWARE\YourProduct" for every user found
                If My.Computer.Registry.Users.OpenSubKey(UserSID & "SOFTWARE\YourProduct\") IsNot Nothing Then
                    My.Computer.Registry.Users.DeleteSubKeyTree(UserSID & "SOFTWARE\YourProduct")
                End If
        Next

'That's it.

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now