2

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.

Community
  • 1
  • 1
mjsr
  • 7,410
  • 18
  • 57
  • 83

1 Answers1

0

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.

vcsjones
  • 138,677
  • 31
  • 291
  • 286
  • thanks i add another project to my solution that do the elevated things and from the non elevated i add your code to launch the resulting exe of the first project . It works exactly as i need. – mjsr May 02 '11 at 18:47