how can i replace a file asking for elevation [duplicate]
Possible Duplicate:
Request Windows Vista UAC elevation if path is protected?
Hi all, i need to overwrite some specific file in c:\program files...., for UAC i don't have writing permissions to that file, and here is my question how can i ask for elevation to overwrite that file? The code is written in c# and is a Windows Forms app.
You can start another process with elevated permissions, using the runas
verb when starting the process.
Something like this:
ProcessStartInfo info = new ProcessStartInfo("pathtoyourexecutable.exe");
info.Verb = "runas";
Process process = new Process();
process.StartInfo = info;
process.Start();
I don't think there is any way to get out of needing to create a new process, it can't be done at the Thread level. You could use Out-of-Process COM objects, but that's even more trouble.
精彩评论