简体   繁体   中英

Not able to run exe from powershell for a system user

I am trying to run an exe from powershell script on windows-7 64 bit machine. In this script I want to run exe as another user. It works when user invoking script is an actual user. But in my case, this powershell script will be executed from system user account and for system user script does not work. Here in a simple code I am using to open notepad. This code fails for system user.

$username = 'MyDomain\MyUser'
$password = 'mypswd'
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))
Start-Process -Credential $cred  "notepad.exe"

I have set execution policy to unrestricted. When I run this script for system user, then I get error as

Start-Process : This command cannot be executed due to the error: Access is den ied. At D:\\temp\\trythis.ps1:4 char:14 + Start-Process <<<< -Credential $cred "notepad.exe" + CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOp erationException + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.C ommands.StartProcessCommand

Is there any way in which I can run this script for system user?

The most likely problem here is a permissions one (The only way I could reproduce your issue was by setting a Deny entry for the account).

I would suggest the following to confirm the permissions are correct. Instructions are for Windows XP, SP3 - adjust for your version!

  1. Right-click on "notepad.exe" and click Properties
  2. Click the Security tab
  3. Click the Advanced button
  4. Click the Effective Permissions tab
  5. Click the Select... button
  6. Enter the account you want to check and confirm that the account has appropriate read and execute permissions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM