4

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?

Maanu
  • 5,093
  • 11
  • 59
  • 82
  • 2
    If you figure out you must write to a protected storage area (because the data is sensitive and shouldn't be written by normal users), there is always the option of leaving your program non-elevated for non-elevating actions, and writing a separate piece that gets elevated to perform write actions. – Merlyn Morgan-Graham Jun 01 '11 at 15:26
  • @Merlyn Morgan-Graham: I did not get that idea. Where can I get more info on this? – Maanu Jun 01 '11 at 15:40
  • This might be old info, not sure - Create a second executable to perform administrative write actions. Call it using `Process.Start`, with the `Verb` property set to `runas`. Put icons on your UI to make it obvious that you're doing an admin-required action, and that elevation may be required (the shield icon - see the User Accounts control panel for a visual example). See http://en.wikipedia.org/wiki/User_Account_Control#Requesting_elevation, and this question: http://stackoverflow.com/questions/923350/delphi-prompt-for-uac-elevation-when-needed – Merlyn Morgan-Graham Jun 01 '11 at 15:48

4 Answers4

3

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?

Danny Varod
  • 17,324
  • 5
  • 69
  • 111
  • The applications write information like no:of days expired in the evaluation period in the regisrty – Maanu Jun 01 '11 at 15:27
  • 1
    @Maanu: Can you calculate the expiration date at install time? Then you only need to read it at runtime. – bk1e Jun 01 '11 at 15:41
3

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.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
2

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

IAmTimCorey
  • 16,412
  • 5
  • 39
  • 75
  • 1
    I have to give permission to write in certain folders of Program files for all users. How can I do that? – Maanu Jun 01 '11 at 15:28
  • 1
    @Maanu - If you REALLY want to allow users to write to a Program Files folder, you will need to change the folder permissions (which will require a UAC prompt at setup). However, I would suggest instead that you store any files in a central place that doesn't need UAC prompts such as CommonApplicationData (which, by the way, is what that folder is for). – IAmTimCorey Jun 01 '11 at 15:30
  • Thanks. The applications were written several years back. These applications create folders like Logs,Recipes etc in the installed folder. Changing the behavior for Windows 7 will need some amount of investment – Maanu Jun 01 '11 at 15:39
  • @Maanu - I feel your pain. Unfortunately, this is a big no no (http://stackoverflow.com/questions/1191941/file-write-permission-issue-under-program-files-folder, http://stackoverflow.com/questions/946420/allow-access-permission-to-write-in-program-files-of-windows-7) However, as a temporary measure, could you change your install directory? I know it isn't common or recommended, but it might be a temporary work-around. – IAmTimCorey Jun 01 '11 at 15:48
1

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.

GaryO
  • 5,873
  • 1
  • 36
  • 61