Self-Updating .NET client application which needs to write in the Program File folder

会有一股神秘感。 提交于 2019-12-11 00:35:19

问题


Similar to: Request Windows Vista UAC elevation if path is protected?

I have a .NET Client Application installed in c:\Program Files (Windows Vista). This application should update itself, but it doesn't because of permission issues. The auto-updater should simply replace a couple of assemblies, but they are all located under c:\Program File and the application throws the following exception:

System.UnauthorizedAccessException: Access to the path 'C:\Program Files...' is denied.

I have no control on where the application could be installed and the permission. Is there any workaround for this? Is it possible to request the Administrator rights for a couple of seconds? Is it possible to pop a UAC window? I am pretty sure that there a workaround... Otherwise, how Firefox would be able to update itself?

Thanks in advance for the help and ideas!


回答1:


Could you use a Click Once deployment method? We use this for an internal application and users have no problems with permissions when we publish a new version. They are prompted to install the update when they launch the app (if a new version exists) and it installs without a hitch.




回答2:


You can't elevate a process's permissions halfway through, but you can start up another separate process with higher permissions that can do the work for you.

Get your main application to put all the files / installation details into a low-permission temporary location. When you're ready, start up a smaller application whose only job is to copy over those files to the Program Files directory (and maybe restart your main application with the new updates). Mark that application as requiring the needed permission to copy to the Program Files directory or write to the registry (or whatever else is needed).



来源:https://stackoverflow.com/questions/524875/self-updating-net-client-application-which-needs-to-write-in-the-program-file-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!