MaliCMT
MaliCMT

Reputation: 31

Process.start () throwing error while trying to run as administrator

I have an application developed in vb.net which needs administrator privileges. I have set level = "requireAdministrator" in the application manifest. My client wants this application to be run by a local user due to some restrictions in their organization. So I created another ‘Launcher’ application which will actually save an administrator credentials in an encrypted format and will use the saved credentials to run the ‘Original’ application.

Everything works fine if I’m using the ‘Administrator’ account (Built-in account). But if I’m using the credentials of the manually created administrator account – the process.start () line is throwing an error “The requested operation requires elevation” I really couldn’t identify the difference between the built-in administrator and manually created administrator account. I confirmed that both the users (built-in and manually created) are members of Administrators and HomeUsers. I tried all possibilities by creating different users with different user groups and even with different OS (windows 7 and Windows 10 – both 32 and 64 bit versions) – but, all are working in the same manner as explained above. Is there anything that I have to change in my code?

     Dim psi As New System.Diagnostics.ProcessStartInfo()
        psi.FileName = (AppToStart)
        psi.RedirectStandardError = True
        psi.RedirectStandardOutput = True
        psi.CreateNoWindow = True
        psi.UseShellExecute = False
        psi.UserName = TbUser.Text
        psi.Password = ConvertToSecureString(TbPass.Text)
        psi.Domain = ""
        Dim p As Process = Process.Start(psi)

Additional Info: Here I'm running this 'Launcher' application as a standard user (not administrator) and the application works well and it really elevates the privileges if

TbUser.Text = “Administrator” and TbPass.Text = 123 (Administrator password).

But this is not elevating privileges if

TbUser.Text = “Adminuser” (which is also an administrator belongs to the same ‘Administrators’ group) and TbPass.Text = 321 (password for Adminuser).

Upvotes: 3

Views: 815

Answers (1)

Trevor
Trevor

Reputation: 8004

Unfortunately you can't do this and here is why...

Basically verb isn't recognized when psi.UseShellExecute = False, this would need to be psi.UseShellExecute = True. You are doing this while trying to use runas as an elevated permission.

In your situation, you would not use the verb = runas, make sure the application has already been started with the correct permissions.

Please see more here about elevating privileges, Hans Passant say's it best...

Upvotes: 1

Related Questions