2

How can I elevate my program on demand? (For example when clicking a button). I don't like to set the privileges in the manifests file, I am talking about elevating my VB.Net program at runtime. Does anyone know how to do this? I appreciate every helpful answer :)

Madara Uchiha
  • 127
  • 2
  • 11

2 Answers2

1

You can't elevate your program on demand as such. Your options are:

Community
  • 1
  • 1
Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
0

Okay, using the RunAs-Method to elevate it. (This requires a restart tho)

Private Sub RestartElevated()
    Dim startInfo As New ProcessStartInfo()
    startInfo.UseShellExecute = True
    startInfo.WorkingDirectory = Environment.CurrentDirectory
    startInfo.FileName = Application.ExecutablePath
    startInfo.Verb = "runas"
    Try
        Dim p As Process = Process.Start(startInfo)
    Catch ex As System.ComponentModel.Win32Exception
        Return
    End Try

    Application.[Exit]()
End Sub
Andreas
  • 5,393
  • 9
  • 44
  • 53
Madara Uchiha
  • 127
  • 2
  • 11