2017-02-17 9 views
1

古いゲームディスクからコピーしたISOファイルがあります。しかし、私がゲームをプレイするためには、ISOをマウントする必要があります。 .ps1 PowerShellファイルを実行してISOをマウントし、EXEを実行してマウントした後にゲームを開始する小さなバッチファイルを作成しました。私の問題は、スクリプトを2回以上実行すると、再び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" 

答えて

2

それがマウントされていない場合は、このスニペットは画像のみをマウントします:

if(!(get-DiskImage -ImagePath C:\testshare\97001.ISO).Attached){ 
Mount-DiskImage -ImagePath C:\testshare\97001.ISO 
} 
0

をアブヒジスの答えを補完するために、特に私が以前に戦わなければならなかった1個のバグを言及します:

$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  
} 
関連する問題