Ask Kathleen Listing 1: Elevate Your Privileges
Private Sub ElevatePrivileges()
Dim startInfo As New Diagnostics.ProcessStartInfo
startInfo.UseShellExecute = True
startInfo.WorkingDirectory = Environment.CurrentDirectory
Dim mainExecutable As String = _
Windows.Forms.Application.ExecutablePath
Dim mainPath As String = _
IO.Path.GetDirectoryName(mainExecutable)
startInfo.FileName = IO.Path.Combine( _
mainPath, "UAC Test Elevated.exe")
startInfo.Verb = "runas"
startInfo.ErrorDialog = True
startInfo.ErrorDialogParentHandle = _
Me.Handle
Try
Dim process As Diagnostics.Process = _
Diagnostics.Process.Start(startInfo)
process.WaitForExit()
Catch
MessageBox.Show( _
"Failed to gain administator privileges")
Return
End Try
End Sub
Listing 1: Vista provides elevated privileges per process.
To manage UAC in Vista, isolate your administrator tasks into an application that will run in a separate process. Use a manifest to demand elevated privileges for this ancillary process, and Vista will not open it if the user does not explicitly allow the privilege elevation and provide administrator credentials.