locked
Process.Start - "requested operation requires elevation" RRS feed

  • Question

  • I'm using code in VB.NET to launch an executable from a share, the code works fine for some install files, but not for all.  Some of the executables when started generate an error - requested operation requires elevation.  Here's the code:

                    Dim p As New ProcessStartInfo()
                    Dim fileInfo As New FileInfo(InstallPath)
                    p.LoadUserProfile = True
                    p.UseShellExecute = False
                    p.Arguments = ""
                    p.ErrorDialog = True
                    p.CreateNoWindow = True
                    p.ErrorDialogParentHandle = Handle
                    p.Verb = "runas"
                    p.WindowStyle = ProcessWindowStyle.Normal
                    p.Domain = Domain
                    p.UserName = Character
                    p.WorkingDirectory = fileInfo.DirectoryName
                    p.FileName = InstallFile
                    p.RedirectStandardOutput = True

                    p.Password = New System.Security.SecureString()
                    For Each c As Char In Authenticator
                        p.Password.AppendChar(c)
                    Next

                    Dim pr As New Process()
                    pr = Process.Start(p)
                    pr.WaitForExit()

    Thanks.

    In my code, I'm using a username and password other than the desktop user's credentials to access the share.  If the answer to my problem is to elevate permissions programatically, can I still do this if I'm accessing the share with a standard username other than the client's?

    Could the solution be as easy as just changing the compatibility settings on the install files?

    What about adding a UAC shield icon to the button that executes the above code?  Does adding the icon to the button force the user to elevate via a prompt, or am I supposed to add the icon programmatically only when I know the user will be prompted?

    Wednesday, December 1, 2010 7:08 AM

Answers

All replies

  • If these executables are already indicated as requiring admin, you don't need to specify runas here.

     

    Thursday, December 2, 2010 6:15 PM
  • Thanks for your reply David, specifiying "runas" has no impact on whether or not the code functions.  As for some of my questions:

    "Could the solution be as easy as just changing the compatibility settings on the install files?"

    Answer is no.

    "What about adding a UAC shield icon to the button that executes the above code?  Does adding the icon to the button force the user to elevate via a prompt, or am I supposed to add the icon programmatically only when I know the user will be prompted?"

    Adding the icon does not force the user to elevate.

    New option: CreateProcess and CreateProcessAsUser.  CreateProcess works for the same executables as my Process.Start code but at least my code allows me to impersonate another user.  I am now trying to implement CreateProcessAsUser, maybe it will work.

    Thursday, December 2, 2010 6:32 PM
  • CreateProcessWithLogonW turned out to be the API I needed. While I can't use it to elevate permissions, I can use it to call a bootstrapper which will in turn call the software executables.

    http://blogs.msdn.com/b/cjacks/archive/2010/02/01/why-can-t-i-elevate-my-application-to-run-as-administrator-while-using-createprocesswithlogonw.aspx

     

    • Marked as answer by Alba314271 Sunday, December 5, 2010 8:09 PM
    Sunday, December 5, 2010 8:05 PM