Dim proc As New ProcessStartInfo proc.UseShellExecute = True proc.WorkingDirectory = "c:\debug" proc.FileName = "test.exe" proc.Verb = "runas" If IsRunAsAdmin() = False Then Try Process.Start(proc) Application.Exit() Catch ' The user refused to allow privileges elevation. MsgBox("Permission denied by user ! Can not proceed.", MsgBoxStyle.Critical) Return End Try Else MessageBox.Show("Already Running as Admin") End If End Sub
Friend Function IsRunAsAdmin() As Boolean Dim principal As New WindowsPrincipal(WindowsIdentity.GetCurrent) Return principal.IsInRole(WindowsBuiltInRole.Administrator) End Function
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)