Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between runas.exe and Start-Process -Credential

I am playing around with setting up some scripts on a vpn on a client's network. This client generally assigns an ActiveDirectory account on their network and use it to manage permissions (eg. to databases). Ok, that makes sense.

But here is something that confuses me:

start-process runas.exe "/user:CLIENTDOMAIN\George.Mauer /netonly W:\tools\LINQPad4\LINQPad.exe

queries for a password and runs just fine (and I can access the database)

But

Start-Process W:\tools\LINQPad4\LINQPad.exe -Credential (Get-Credential)

and entering CLIENTDOMAIN\George.Mauer and my password at the popup prompt always results in an error

Start-Process : This command cannot be run due to the error: The user name or password is incorrect.

Are these not the same thing? What's the difference between runas and -Credential? And a secondary question - how do I Start-Job with my CLIENTDOMAIN\George.Mauer credential?

like image 1000
George Mauer Avatar asked Mar 25 '13 03:03

George Mauer


People also ask

What is start-process PowerShell?

The Start-Process cmdlet starts one or more processes on the local computer. By default, Start-Process creates a new process that inherits all the environment variables that are defined in the current process.

How do you use runas in PowerShell?

Step 1: Press the Windows + R keys together to bring up the Run dialog box. Step 2: Type the PowerShell in the box and click OK button. A normal Window PowerShell will launch as a current user. Step 3: Type the command start-process PowerShell -verb runas and press "enter" key.

How do I Run a process in the background in Windows PowerShell?

The Start-Job cmdlet starts a PowerShell background job on the local computer. A PowerShell background job runs a command without interacting with the current session. When you start a background job, a job object returns immediately, even if the job takes an extended time to finish.

How to launch a program using another user using runas command?

You just need to launch the installer from command prompt using runas command and by providing administrator login id and password. Let’s see the syntax of runas command with some examples. The command to launch a program using another user credentials is given below.

What is runas command in Windows 10?

The runas command also lets you to save the user’s password to the Windows Credential Manager so that you don’t have to enter it every time. Open the command prompt (or the Run window by pressing Win+R ).

How do I run an EXE file with PowerShell?

The Verbs property of the ProcessStartInfo object shows that you can use the Open and RunAs verbs with PowerShell.exe, or with any process that runs a .exe file. Both commands start the Windows command interpreter, issuing a dir command on the Program Files folder.

How do I run a program from the main executable?

Find the program's main executable in File Explorer. Select it, and then click or tap on the Manage tab from the ribbon. The option you need is displayed in the Run section of Application Tools.


1 Answers

/netonly runs the process as the current user and only network connections are made with the other credentials.

Start-Process will run the process (and all its network connections) with the other credentials. There's no way to achieve the /NETONLY functionality with Start-Process.

You'd have to p/invoke the Win32 API to achieve /NETONLY functionality. If you're up for the exercise this is the API you'll need to use LOGON_NETCREDENTIALS_ONLY with:

http://www.pinvoke.net/default.aspx/advapi32/createprocesswithlogonw.html

More resources:

  • example code with LOGON_NETCREDENTIALS_ONLY
  • CreateProcessWithTokenW function

To run a job as a different user:

Start-Job -ScriptBlock {whoami} -Credential (get-credential) | Wait-Job | Receive-Job
like image 150
Andy Arismendi Avatar answered Oct 08 '22 08:10

Andy Arismendi