简体   繁体   中英

script working in Visual studio but not when running from Batch file

I have a script which supposed to run powershell with different credentials and then in that session supposed to goto network path and install a file:

$path1 = "\\192.168.10.10\bucket\test.exe"
Start-Process powershell -Credential $creds -ArgumentList "-Command &{Start-Process $path1 -Verb RunAs}"

looks like no problem running this from the ISE but when i save the ps file and tried to call it from batch file i get the folowing error: 在此处输入图像描述

What could be the reason for that?

When you use Start-Process with the -Credential parameter, whatever happens to be the caller's current directory matters:

If the target user identified by the -Credential argument happens not have the required permissions to access the caller 's current directory, you'll get the error you saw.

The solution:

  • Use the -WorkingDirectory parameter to specify a current (working) directory for the new process that the target user is allowed access to.

  • Alternatively, switch to such a directory in the caller 's context first.

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