Maanu
Maanu

Reputation: 5203

HKLM registry doubt

My application updates some registry fields related to licensing under HKLM. This is for accessing the information for all users in the system. This makes us to make our application run as administrator. Is there any other location in registry where I can keep information which can be accessed by all users?

Upvotes: 4

Views: 246

Answers (4)

GaryO
GaryO

Reputation: 6338

I'd make your installer precreate the registry entries (it runs as admin typically), and open up their permissions using GetSecurityInfo and SetSecurityInfo. Then your app can write to them without any special perms.

Upvotes: 1

Uwe Keim
Uwe Keim

Reputation: 40726

You could place as an (e.g.) XML document in the file system under a shared folder instead of the Registry.

E.g. System.Environment.SpecialFolder.CommonDocuments or CommonApplicationData.

Upvotes: 3

Danny Varod
Danny Varod

Reputation: 18069

Registry HKLM and folder %ALLUSERSPROFILE% are accessible to all users, but meant for writing to at install time (as admin).

Registry HKCU and folder %APPDATA% are accessible to current user and meant for writing to at any time.

Why are you modifying licensing info (shared by all users) during run and not just during install?

Upvotes: 3

IAmTimCorey
IAmTimCorey

Reputation: 16757

No there is not. If you have to make a modification that will affect/be visible to all users, you have to deal with UAC or elevate your application on startup. This is part of the design of UAC. If, however, you were to write to a file you could grant all users access to that file without UAC interference.

If, however, you are only reading the registry, you can do this without elevating your security rights. Therefore, if you write once to the registry and then just read it later, you can do so when only elevating your privileges once.

Here is an article on playing nice with UAC:

http://msdn.microsoft.com/en-us/magazine/cc163486.aspx

Upvotes: 2

Related Questions