我正试图从安装到DriveLetter:\的iso文件中运行"AutoRun.exe"
& "${DriveLetter}:AutoRun.exe"
使用上面的方法,我可以正确地告诉PowerShell运行可执行文件,但它希望支持文件(AutoRun.cfg等)位于执行位置(在这种情况下是我的Desktop)。我希望无论PowerShell脚本的位置如何,都能正常工作。
有什么建议吗?
更改所需文件所在的工作目录。如果它们位于${DriveLetter}:
中,则更改为该目录:
Set-Location "${DriveLetter}:"
& "${DriveLetter}:AutoRun.exe"
如果它们与PowerShell脚本位于同一文件夹中,请更改为该目录:
Set-Location (Split-Path -Parent $MyInvocation.MyCommand.Definition)
& "${DriveLetter}:AutoRun.exe"
或(PowerShell v3及更新版本):
Set-Location $PSScriptRoot
& "${DriveLetter}:AutoRun.exe"