UAC Self Elevation

OSVBNET 1,386 Reputation points

Hello experts,
I found a sample by Microsoft for UAC Self Elevation:

Dim proc As New ProcessStartInfo
proc.UseShellExecute = True
proc.WorkingDirectory = Environment.CurrentDirectory
proc.FileName = Application.ExecutablePath
proc.Verb = "runas"
' The user refused to allow privileges elevation.
' Do nothing and return directly ...
End Try

I need to run this from my app which is not admin.
Adding some keys to HKLM is needed, just wonder which process to start?
Don't want my whole app to get admin rights, just add some registry keys.
Can I make a reg file and use the above code? or some better ways to do it?
Thanks for helping :)

An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,502 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 38,866 Reputation points

    Yes, you can use a .reg file. Keep in mind that UAC will ask for an Administrator's credentials if the application is started from a non-Administrator account.

    For demo purposes the .reg file is in the non-admin account's Documents folder. The "/s" switch tells regedit not to issue a confirmation prompt.

    Module Module1  
        Sub Main()  
            Using proc As New Process()  
                    proc.StartInfo.UseShellExecute = True  
                    proc.StartInfo.Verb = "runas"  
                    proc.StartInfo.FileName = "regedit.exe"  
                    proc.StartInfo.Arguments = "/s " + Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\Bozo.reg"  
                Catch ex As Exception  
                    Console.WriteLine($"Exception: {ex.Message}")  
                End Try  
            End Using  
        End Sub  
    End Module  

0 additional answers

Sort by: Most helpful