2

I'm creating a powershell script that does some automatic setup of new computer deployments. I'm in a situation where I want to launch an executable as a regular non-admin user from an elevated admin powershell console instance. The reason why is because if I launch from an elevated prompt/script, the executable generates an error. Here's the structure of the command:

Start-Process -FilePath (${Env:CommonProgramFiles(x86)} + "\sample.exe") -ArgumentList "/PRODUCT:sample", "/VERSION:2.0", "/MODE:1"

I did some searching and found the opposite of what I need (non-admin to admin) here https://technet.microsoft.com/en-us/library/hh849848.aspx but I only saw RunAs to elevate to admin.

Setup:

  • Windows 10 Education
  • PS 5

Resolution

Since psexec didn't offer a solution for suppress login, I ended up starting the process as follows:

 $username = Read-Host "Please enter in a valid username "
 $password = Read-Host "Please enter in a the account password " -AsSecureString
 Start-Process -Credential (New-Object System.Management.Automation.PSCredential($username, $password)) -FilePath (${Env:CommonProgramFiles(x86)} + "\sample.exe") -ArgumentList "/PRODUCT:sample", "/VERSION:2.0", "/MODE:1"

It doesn't solve the issue perfectly, but the user can stay in the script at least.

3 Answers 3

1

It depends on what the issue is. If you are not running under a user context at all, like under the SYSTEM account, then you might need to run as a particular user, which typically means specifying a username and password, which is often problematic.

If the issue is that you currently have admin rights, but need to run something without those admin rights, then this should be possible using PSExec or similar methods without needing a Username & Password.

psexec -accepteula -l <CMD>

-l Run process as limited user (strips the Administrators group and allows only privileges assigned to the Users group). On Windows Vista the process runs with Low Integrity.

It should be possible to call PSExec within PowerShell and have PSExec call the original application. It may also be possible to do this through PowerShell directly.


It may also be possible to do this with PSExec without needing a username / password to be entered by executing something within the session of the target user as long as they are already logged in.

psexec -accepteula -i <session> <CMD>

3
  • 1
    I found a not-so-clean way to circumvent this, but using psexec makes it cleaner for sure.
    – djthoms
    Jun 14, 2016 at 15:58
  • You should share the method you came up with if you can. You could answer your own question.
    – jgstew
    Jun 14, 2016 at 16:43
  • 1
    Updated the question with my solution
    – djthoms
    Jun 14, 2016 at 19:52
1

In my own scripts I use psexec in those situations.

You have to specify username and password for a different account as well as an executable which then runs as the specified user.

This is not pure PowerShell but good enough for me. It may be possible for a PowerShell script to do the same thing psexec does. But unless you find out, this should solve your problem.

0

I found a more elegant way to do this in the following source: https://stackoverflow.com/a/29271474/10875044 My ps1 is executed with admin privilege, and I just use explorer.exe to launch my process with normal running privilege, e.g.: Start-Process explorer.exe -ArgumentList C:\SysJust\XQLite\daqxqlite.exe

Even thought the ps1 is elevated, the explorer.exe will launch the program in non-admin privilege, which is what I need.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .