Archive: Hkey_current_user


Hkey_current_user
In my app, I store registry values in HKEY_CURRENT_USER. When I uninstall my app, how do I make sure to delete all those values? If the user uninstalls under a different username than he ran the app, then some registry values would be left behind. Putting values in HKEY_CURRENT_USER is common enough, so NSIS must have some easy way to delete them :)


I think HKCU is intended to be for the current user and as far as I know the current user do not have any access to the registry tree of the others (maybe by HKU but I don't know how).
To give all users the opportunity to uninstall your app properly you could write your registry settings to HKLM like NSIS does it.

~ Florian


Using HKCU makes things easier for me :)

Here's how I fixed it:

I just put the following in my app's (WulframPoller) Uninstall section:

IntOp $0 0 + 0
EnumStart:
EnumRegKey $R1 HKEY_USERS "" $0
IntOp $0 $0 + 1
StrCmp $R1 ".DEFAULT" EnumStart
StrCmp $R1 "" EnumEnd
DeleteRegValue HKU "$R1\Software\Microsoft\Windows\CurrentVersion\Run" "WulframPoller"
DeleteRegKey HKU "$R1\Software\Wulfram Poller"
Goto EnumStart
EnumEnd:

Probably could be done in a more efficient way, but it gets the job done :)


I don't know of any way to delete for every CU there is... What I have done in my app was to create an uninsatller for every user.

This code is located in my user installer. It causes two uninsallers to display in the Add/Remove control panel, one of the program it self, and one for the user's settings.

WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\BlazeRunSettings" "DisplayName" "BlazeRun Current User Settings"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\BlazeRunSettings" "DisplayIcon" "$1\BlazeRun.exe"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\BlazeRunSettings" "UninstallString" '"$1\UserUninstall.exe"'


KiCHiK

The way I did *should* delete for every user, if I'm understanding the Registry correctly :)


I must say your way is much better than mine!
Good work. :up:

Live and learn ;)


Thanks for the info. IGx89 - this is a very useful registry tip/scriptlet. :D

I never would have guessed this would work since when I fire up my registry editor I only see data for the current user in HKEY_USERS...

Just to clarify though: even though I can't see the data (via regedit) for the other profiles, I can still delete it? And it'll work in 9x and NT? (I'll test it out when I can, but external affirmation is soooo comforting ;))


HKEY_CURRENT_USER (HKCU) is only the info for the current user. HKEY_USERS has a list of username keys, under which is the contents of HKCU. Basically, HKCU is a quick, no-hassle shortcut to the current user's info under HKEY_USERS. Hope I'm clear enough :)

As for working under W9x/NT, it's worked fine for me under W98. I tested NT4, and it seemed to work fine, though I didn't test it too much. It *should* work just fine, since it seems to use HKCU and HKU the same way as W98.


Thanks for the info. - I thought HKCU was kind of a shortcut/minor of info. for the current user that's stored elsewhere in the registry. I think a fair bit of the registry keys are linked/mirrored in that fashion.

Glad to hear it works on 98 and NT4 - I can't wait to wrap up upgrading to 1.95 myself and begin testing my installer. :)

Ahh, the soothing tedium of repetitive installation testing... ;)

Thanks again IGx89. :D


I am not sure about Windows 9x but on NT HKEY_USERS only holds the logged on users and the default user.

HKEY_USERS - Registry entries subordinate to this key define the default user configuration for new users on the local computer and the user configuration for the current user.

It took you that long to reply? :eek:
;)


Someone refered to this post, from another post and when I read it again I saw that it's wrong. Better late than never :D


It certainly makes sense from a 'security' point of view that other user's registry entries are unavailable under HKEY_USERS in NT. ;)

I don't have 9x anymore, but I think I tested it on there and managed to delete keys from other profiles.


Originally posted by IGx89
Using HKCU makes things easier for me :)

Here's how I fixed it:

I just put the following in my app's (WulframPoller) Uninstall section:

IntOp $0 0 + 0
EnumStart:
EnumRegKey $R1 HKEY_USERS "" $0
IntOp $0 $0 + 1
StrCmp $R1 ".DEFAULT" EnumStart
StrCmp $R1 "" EnumEnd
DeleteRegValue HKU "$R1\Software\Microsoft\Windows\CurrentVersion\Run" "WulframPoller"
DeleteRegKey HKU "$R1\Software\Wulfram Poller"
Goto EnumStart
EnumEnd:

Probably could be done in a more efficient way, but it gets the job done :)
Nice idea.
But on my systems (2000/XP) I see only the ".DEFAULT" key and the key (SID?) for the current user on the hive "HKEY_USERS". No matter if I logged on as admin or user.
So for this reason the enumeration stops after deleting the keys for the current user.

Any idea about what's wrong with my system?

BTW: Writing application settings to the ".DEFAULT" key to prepare the system for new users has no effect.
If I add a new user he never gets this setting.

I am completely helpless
:rolleyes:

Nothing is wrong on your computer, that's how it works. You can use EnumUsersReg to load the users' hives manually.


Originally posted by kichik
Nothing is wrong on your computer, that's how it works. You can use EnumUsersReg to load the users' hives manually.
Many thanks to you, kickik. :up:

That's what I was looking for. :D

Allow me still two further questions:

Is there an easy way to call this functions in uninstall section without copying them and adding the un. prefix to the function name?

The hive "HKU\.DEFAULT" does not work as I had expected.
If I add a new user to my system he does not get the settings I wrote to "HKU\.DEFAULT" at installation time.
Any suggestion how to ad this for new users?

Mikesch

Has anybody thought about the fact that, if the user who is running the uninstaller doesn't have administrative rights, the installer won't be able to delete the registry values of the other users?

Greetings,

Fretje


Originally posted by Fretje
Has anybody thought about the fact that, if the user who is running the uninstaller doesn't have administrative rights, the installer won't be able to delete the registry values of the other users?

Greetings,

Fretje
Yes, I thought about this fact.

I need the above behaviour for the case of installing my application as an administrator for all users.
If a normal user installs my application he does this only for itself and does not affects any other user settings.

In this moment I work on my uninstaller section to prevent uninstalling by the user if the application was installed by an administrator.

Mikesch

You can put the functions in a macro and insert once for the installer and once for the uninstaller.

!macro func un
Function ${un}blah
FunctionEnd
!macroend
!insertmacro blah ""
!insertmacro blah "un."
I don't know why HKU\.DEFAULT doesn't work.

IIRC: HKEY_CURRENT_USER can be roaming in Windows networks using a domain controller. Therefore I think it's a bad idea to delete those data for all/other users. HKEY_CURRENT_USER should only contain user settings. Because you cannot know how many network computers (0 or more) have your software installed I would let that data alone. Giving some option to uninstall user settings for the current user may be ok. Or you may give each user the possibility to remove that data by some small uninstall_userdata.exe/regclean.exe separately (an admin could push this to something logon.bat if he wants to clear the whole network).