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 = 'MyDomainMyUser'
$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:temptrythis.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!

  • Right-click on "notepad.exe" and click Properties
  • Click the Security tab
  • Click the Advanced button
  • Click the Effective Permissions tab
  • Click the Select... button
  • Enter the account you want to check and confirm that the account has appropriate read and execute permissions.
  • 链接地址: http://www.djcxy.com/p/29084.html

    上一篇: 无法在服务器计算机的网络中的所有计算机上运行PowerShell脚本

    下一篇: 无法从系统用户的powershell运行exe