Prompt with UAC when user doesn't have access to copy a file
In my application, if the user saves a file to a folder they don't have permissions for, File.Copy
will fail. An example is saving a document to the C:\ root.
Instead of denying access, I'd like to prompt the user to elevate permissions with a UAC开发者_如何学C prompt, but only for this save function (not for the entire application). Is there a way to do this?
In short... no.
The entire process needs to be elevated and that elevation needs to happen at startup. However! You can create a separate process to do this work. Make a separate .exe that does only this work and gets everything it needs in the command line parameters. You can add verbs to the process that will cause it to be elevated:
Process p = new Process();
p.StartInfo.FileName = "copy.exe";
p.StartInfo.Arguments = new [] { pathFrom, pathTo };
p.Verb = "runas";
p.Start();
Something like that...
精彩评论