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 :)
Asked
Active
Viewed 2,921 times
2 Answers
1
You can't elevate your program on demand as such. Your options are:
- Restart your application using the RunAs verb (see start batch file from within vb.net as admin)
- Start your application with the required privileges in the first place

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