I have an application, which normally runs without need for admin priviliges.
The program includes tool for automatic update (download files from web and replace local files). Depending on location of application in user's computer, some users do not have privileges to manipulate those updated files and therefore automatic update fails.
I would like to implement functionality, which prompts user to run this task as admin (User Access Control window). I already have code which checks, whether user has access to those files, I just do not know, how to invoke User Access Control window (for File.Move
and/or File.Copy
)
I do not want user to run the application as administrator. Admin rights are needed just for file manipulation and only in case when user does not have access to those files already. The application runs on Windows Vista and higher.
Any help is appreciated.
Thanks, Zbynek
UAC is tied to a process. Create a (windowless) helper application for this task that requires administrator privilege in its manifest (as explained here), then invoke that application from your main application using Process.Start (be sure to check for failure, in case the user refuses to elevate). If the user is already elevated, they won't be prompted.
You can use command-line arguments if you need to supply more information to the helper on what to do (which files to copy where).