Quantcast
Viewing all articles
Browse latest Browse all 15744

VS 2015 Launch exe as another user with elevated rights

I have users with non admin rights that need to run a program which requires admin privileges. I thought I'd make a VB.net program to launch that program as a local admin account. I have the below code, but I get the error, "The requested operation requires elevation." I read that UseShellExecute needs to be set to false to use "verb = runas", but then that produces the error, "The Process object must have the UseShellExecute property set to false in order to start a process as a user." So I think launching the program as another user requires UseShellExecute to be false, but "verb = runas" requires UseShellExecute to be true. Does anyone know how I can get this to work?

Code:

    Private Sub launchProgramWithUser()
        Dim pstartinfo As New ProcessStartInfo("C:\Program Files (x86)\Program123\program123.exe")
        pstartinfo.WorkingDirectory = "C:\Program Files (x86)\Program123"
        pstartinfo.UserName = "User1"
        Dim pwd As New System.Security.SecureString
        pwd.AppendChar("a"c)
        pwd.AppendChar("c"c)
        pwd.AppendChar("s"c)
        pwd.AppendChar("2"c)
        pwd.AppendChar("7"c)
        pwd.AppendChar("2"c)
        pwd.AppendChar("0"c)
        pwd.AppendChar("a"c)
        pwd.AppendChar("5"c)
        pwd.AppendChar("8"c)
        pwd.AppendChar("2"c)

        Try
            pstartinfo.Password = pwd
            pstartinfo.UseShellExecute = False
            pstartinfo.Verb = "runas"
            Dim proc As New Process
            proc.StartInfo = pstartinfo
            proc.Start()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub


Viewing all articles
Browse latest Browse all 15744

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>