3

Other people have asked similar questions but I want to clarify. I want to build my application without the need for administrative permissions when installing. For the file association I understand that I need to write in the registry but so far I have found two different locations in stackoverflow articles:

HKEY_CURRENT_USER\Software\Classes

and another under

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts

So which is one the right one?

kaiz.net
  • 1,984
  • 3
  • 23
  • 31
Dimitris
  • 2,030
  • 3
  • 27
  • 45

2 Answers2

6

You should use the former (HKCU\Software\Classes), because that's what Windows uses to open files.

I'm not sure what the second one is used for; I believe it's only used to populate the recommended section of the Open With dialog.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • I tried to write in this location and I can't do it either. Have in mind that our IT has given me a lot more permissions than most people. – Dimitris Mar 14 '12 at 17:07
2

Sadly this is not possible. You will need admin rights in order to do this, there is no way around that.

You can however let the user install the application without admin rights and give him the opportunity to associate the file extensions later on, where you would ask for elevated rights.

Besides that there is no way of accomplishing what you want.

ntziolis
  • 10,091
  • 1
  • 34
  • 50
  • Sadly, the only programs that I've seen do this are viruses. – SLaks Mar 14 '12 at 15:47
  • That's the first time I encounter that. So far everything I 've read talks about no need for admin rights. Can you clarify a bit? – Dimitris Mar 14 '12 at 15:47
  • 1
    @SLaks Have tried to register extensions during install in the past and always needed elevated privileges, maybe this depends on how you UAC is setup? Should add that this was in a corporate environment where the user has pretty limited rights – ntziolis Mar 14 '12 at 15:49
  • So I presume that the only way is to remove file associations from my installer and do it only programmatically. If the user is even more restricted then the code just passes through and does not register the file extension. – Dimitris Mar 14 '12 at 15:57
  • 1
    No quite, the same user will most likely not be able to register the extensions even when doing it programmatic, but at least he can install and use the application, registering the extension is just and easier way for him to use the application. Later on a user with the appropriate rights can then register the extensions for him by executing this code with elevated rights. – ntziolis Mar 14 '12 at 16:06
  • 2
    @ntziolis: Windows has two different sets of extension associations; one in HKLM and one in HKCU. The one in HKCU is always writable, unless you have very evilly wrong ACLs. However, it's rarely used. – SLaks Mar 14 '12 at 16:16
  • @SLaks hm, apparently the admins of those companies were quite paranoid :) – ntziolis Mar 14 '12 at 16:29
  • @ntziolis: They denied write access to **HCKU**? _What_? – SLaks Mar 14 '12 at 16:32
  • 1
    @SLaks most likely not the entire HCKU, maybe just to the file association part, actually that is quite sense able, a lot of malware was doing quite some damage this way a while back – ntziolis Mar 14 '12 at 16:35
  • That actually makes sense. I've seen some nasty malware use this. – SLaks Mar 14 '12 at 16:37
  • 2
    Just to confirm, IT in most places I 've been to is paranoid. We deploy our software in banks and they simply do not allow anything at all. – Dimitris Mar 14 '12 at 16:50