检查.ISO是否已经安装在PowerShell中,如果没有安装
问题描述:
我有一个从旧游戏磁盘复制的ISO文件。但为了让我玩这个游戏,我必须安装ISO。 我写了一个小批处理文件,该文件运行.ps1
PowerShell文件来挂载ISO,然后运行EXE在挂载后启动游戏。我的问题是,如果我多次运行脚本,它将再次安装ISO。检查.ISO是否已经安装在PowerShell中,如果没有安装
我要检查,如果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.exe
PowerShell的
#mounts the image
Mount-DiskImage -ImagePath "C:\Users\Allen\Documents\Games\Hot Wheels Stunt
Track Driver\setup\hot98\HotwheelsStuntTrack.iso"
答
如果它没有安装这个片段将只安装图像:
if(!(get-DiskImage -ImagePath C:\testshare\97001.ISO).Attached){
Mount-DiskImage -ImagePath C:\testshare\97001.ISO
}
答
为了配合阿济斯的答案,特别提到一个错误我以前打:
$imagePath = "the 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
}