问题
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?
回答1:
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.
回答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.
来源:https://stackoverflow.com/questions/9705188/programmatically-add-file-association-without-admin-rights-in-c-sharp