Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run another program as administrator

So I tried Googling this and this does not get a good result. What Im trying to do is run another program as an administrator without that annoying UAC popping up everytime.

The idea is this, this program requires administrator privileges to run which the user will grant. Then this program will run a bunch of other programs that also require administrator permissions. Instead of the user clicking and allowing a bunch of programs time to time, the program with admin permissions can run the other programs as administrator since itself has it.

This would save the user from following way to many instructions. Also, having the program request the user to allow many things looks very unprofessional. Its just a one-click program that does it all.

The reason why I said Google is not getting a good result is because the page is flooded with how users can run their program AS an administrator. I want to be able to run another program as an admin.

I was thinking of dropping the setup files on a folder and then running the files as admin from CMD but it would require me to use runas and after testing it on myself, it kept saying that the password/username was wrong yet I was sure it was.

Any other tips?

like image 543
Steve Laster Avatar asked May 29 '13 01:05

Steve Laster


1 Answers

You can run another application from your application by using:

Process.Start("Notepad.exe")

If your original program is running Elevated (As Admin), then Notepad will run As Admin (there will be no UAC prompt)

If your original program is not running Elevated and you want to start an application elevated (As Admin) you will have to do something like this (this will prompt for elevation):

    Dim procStartInfo As New ProcessStartInfo
    Dim procExecuting As New Process

    With procStartInfo
        .UseShellExecute = True
        .FileName = "Notepad.exe"
        .WindowStyle = ProcessWindowStyle.Normal
        .Verb = "runas" 'add this to prompt for elevation
    End With

    procExecuting = Process.Start(procStartInfo)

Note that there is no way to circumvent the UAC prompt. If UAC is enabled then the user will have to agree to the elevation at some point.

like image 188
Matt Wilko Avatar answered Sep 30 '22 13:09

Matt Wilko