问题
I have a WPF app written in .NET 4.0, VS2010 that I am looking to deploy via clickonce internally on our intranet.
The issue is that I am trying to create a registry key in HKEY_LOCAL_MACHINE, and I am getting access denied.
I have the app set for full trust, and even tried asserting the RegistryPermission to no avail.
Is it truly not even possible to distribute an app via clickonce and have it access HKEY_LOCAL_MACHINE?
回答1:
Not with ClickOnce.
See here for a discussion. Relevant part:
Due to the risk of exposing applications to security elevation attacks, ClickOnce applications cannot request permission elevation if UAC is enabled for the client. Any ClickOnce application that attempts to set its requestedExecutionLevel attribute to requireAdministrator or highestAvailable will not install on Windows Vista.
The last statement also applies to Windows 7, since the security model is the same.
The bottom line is that what you are trying to do requires elevation to "Run as Administrator", so no, you cannot do what you are trying to do with clients whose UAC is turned on.
回答2:
Additionally, if an application needs privileged access to the local machine at install time, then it is definitely not a candidate for ClickOnce deployment because by design there are no mechanisms in ClickOnce to add registry entries, install shared assemblies in the Global Assembly Cache (GAC), install services, and so on.
http://msdn.microsoft.com/en-us/magazine/cc163973.aspx
来源:https://stackoverflow.com/questions/5021021/clickonce-hkey-local-machine