开发者

how can i replace a file asking for elevation [duplicate]

This question already has answers here: 开发者_JAVA技巧 Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜