我有一个ISO文件,它是我从一张旧游戏光盘上复制的。但是为了让我玩这个游戏,我必须安装ISO。我写了一个小的批处理文件,运行.ps1的PowerShell文件挂载的国际标准化组织,然后运行可执行文件,以启动游戏后,它已被挂载。我的问题是,如果我多次运行脚本,它将再次挂载ISO。
我想要检查ISO是否已附加,如果未附加,则挂载它,或者如果已附加,则运行EXE。
下面是我要挂载的ISO:
批处理。
ECHO "Mounting Stunt Track Driver"
@ECHO off
Powershell.exe -executionpolicy remotesigned
-File "C:\Users\Allen\Documents\Games\Hot Wheels Stunt Track
Driver\setup\hot98\mount.ps1"
start /d "C:\Users\Allen\Documents\Games\Hot Wheels Stunt Track
Driver\setup\hot98" stunt.exePowerShell
#mounts the image
Mount-DiskImage -ImagePath "C:\Users\Allen\Documents\Games\Hot Wheels Stunt
Track Driver\setup\hot98\HotwheelsStuntTrack.iso"发布于 2017-02-17 14:35:41
此代码段仅在未挂载的情况下挂载映像:
if(!(get-DiskImage -ImagePath C:\testshare\97001.ISO).Attached){
Mount-DiskImage -ImagePath C:\testshare\97001.ISO
}发布于 2017-02-17 14:50:42
为了补充Abhijith的回答,特别是提到我之前必须解决的一个bug:
$imagePath = "path to your ISO-file"
$mount = Mount-DiskImage -ImagePath $imagePath -PassThru
$driveLetter = ($mount | Get-Volume).DriveLetter
$drive = $driveLetter + ":\\"
# PowerShell bug workaround
# Forces PowerShell to update drive info for its providers
# Not doing so makes Test-Path fail on freshly mounted drives
Get-PSDrive > $null
$setupPath = $drive + "the path to your exe on the mounted drive"
$setupArgs = "your .exe args"
if (!(Test-Path $setupPath)) {
# ... Something went wrong ...
} else {
$process = Start-Process $setupPath -ArgumentList $setupArgs -Wait -PassThru
# You can check $process.ExitCode here
}https://stackoverflow.com/questions/42290665
复制相似问题