开发者

How to run any exe with administrator privileges?

I am using makecert to create certificate i need to do it though c# program the command doesnot execute as it requires ad开发者_开发技巧ministrator privileges.

Please suggest me how to run any exe using administrator privileges in windows 7? If possible than just suggest me the sample code.

Does th o.s. really matters in my case?


Another hint again is using UAC( User Account Control) from the code. Very interestimg source IMHO is this one http://victorhurdugaci.com/using-uac-with-c-part-1/


You can use the RunAs: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/runas.mspx?mfr=true and select an account with the required permissions.


Use the runas verb when starting the process:

ProcessStartInfo info = new ProcessStartInfo(path) { Verb = "runas" };
Process p = Process.Start(info);

This assumes that you are running as a user in the administrator group. In that case the UAC dialog will be shown when the process starts.


Change the manifest of the C# application so that it requires adminstrator privileges. UAC should do the rest to prompt the user and elevate the process.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜