Hack Forums
[.NET] Ask if you want to elevate the permissions of your program or not - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Ask if you want to elevate the permissions of your program or not (/showthread.php?tid=4150593)



Ask if you want to elevate the permissions of your program or not - E3zh00rn - Apr 3, 2014

This will check if your program is run as administrator, if not it will ask you to elevate the permissions or not.

Code
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      If Not My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) Then
      Dim YesNo
      YesNo = MsgBox("You have run the program without administrator rights, would you like to elevate permissions?", MsgBoxStyle.YesNo)
      If YesNo = vbNo Then
            Me.Show()
      Else
            Dim pInf As New ProcessStartInfo
            With pInf
            .FileName = Application.ExecutablePath
            .UseShellExecute = True
            .Verb = "runas"
            .WindowStyle = ProcessWindowStyle.Normal
            End With
            Dim p As New Process
            p = Process.Start(pInf)
            End
      End If
      End If
    End Sub



* - Dispersia - Apr 3, 2014

or simply
Code
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

in appmanifest because if you have to ask for permission then that probably means you're doing something that requires it - hence you don't need to run the application at all if they can't do it.


* - Temploit - Apr 3, 2014

The first part already made me lose faith...


* - E3zh00rn - Apr 3, 2014

(Apr 3, 2014 11:28 AM)Dispersia Wrote:  or simply
Code
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

in appmanifest because if you have to ask for permission then that probably means you're doing something that requires it - hence you don't need to run the application at all if they can't do it.

Thats also a way to do it, but this asks if you want to elevate the permissions.

Code
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
Requires you to ONLY run it as admin.