我有一个ISO文件,我从旧游戏磁盘上复制过来。但是为了让我玩游戏,我必须安装ISO。
我编写了一个小的批处理文件,它运行.ps1
PowerShell文件来挂载ISO,然后运行EXE以在安装后启动游戏。我的问题是,如果我不止一次运行脚本,它将再次安装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.exe
PowerShell的
#mounts the image
Mount-DiskImage -ImagePath "C:\Users\Allen\Documents\Games\Hot Wheels Stunt
Track Driver\setup\hot98\HotwheelsStuntTrack.iso"
答案 0 :(得分:3)
如果未安装图片,则此代码段仅会挂载图片:
if(!(get-DiskImage -ImagePath C:\testshare\97001.ISO).Attached){
Mount-DiskImage -ImagePath C:\testshare\97001.ISO
}
答案 1 :(得分:0)
补充Abhijith的回答,特别是提到我之前必须要打的一个错误:
$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
}