在c#中如何以提升权限的方式重启程序

在c#中重启程序,如果没有Administrator权限,则提示用户,申请权限后再重启程序

string programpath = new System.Uri( System.Reflection.Assembly.GetExecutingAssembly( ).CodeBase ).LocalPath;
// Or for Windows Forms:
// string programpath = System.Windows.Forms.Application.ExecutablePath;
string[] arguments = System.Environment.GetCommandLineArgs( ).Skip( 1 ).ToArray( ); // requires Linq
System.Diagnostics.ProcessStartInfo startinfo = new System.Diagnostics.ProcessStartInfo( );
startinfo.FileName = programpath;
startinfo.UseShellExecute = true;
startinfo.Verb = "runas";
startinfo.Arguments = String.Join( " ", arguments );
System.Diagnostics.Process.Start( startinfo );
System.Environment.Exit( 0 ); // return code 0, change if required
// Or for Windows Forms:
// System.Windows.Forms.Application.Exit( );
日期:2020-04-11 22:50:25 来源:oir作者:oir