【问题标题】:Run Executable (with Support Files) In a Separate Directory在单独的目录中运行可执行文件(带有支持文件)
【发布时间】:2016-05-20 01:03:26
【问题描述】:

我正在尝试从挂载到 DriveLetter 的 iso 文件运行“AutoRun.exe”:\

& "${DriveLetter}:\AutoRun.exe"

使用上述方法,我可以正确地告诉 PowerShell 运行可执行文件,但它希望支持文件(AutoRun.cfg 等)位于执行位置(在本例中是我的桌面)。无论 PowerShell 脚本的位置如何,我都希望它能够工作。

有什么建议吗?

【问题讨论】:

    标签: powershell


    【解决方案1】:

    将工作目录更改为所需文件所在的位置。如果他们驻留在${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"
    

    【讨论】:

      猜你喜欢
      • 2011-01-04
      • 1970-01-01
      • 1970-01-01
      • 2021-04-19
      • 2019-06-08
      • 1970-01-01
      • 2015-10-25
      • 2016-12-16
      • 1970-01-01
      相关资源
      最近更新 更多