投稿コードthisを使用しようとしました。Windows 10でpowershellでビデオを再生
このコードをPowerShellターミナルで直接使用すると、正しく動作します。
Add-Type -AssemblyName presentationCore
$filepath = "C:\Temp\test\Wildlife.wmv"
$wmplayer = New-Object System.Windows.Media.MediaPlayer
$wmplayer.Open($filepath)
Start-Sleep 2
$duration = $wmplayer.NaturalDuration.TimeSpan.Seconds
$wmplayer.Close()
start playing
$proc = Start-process -FilePath wmplayer.exe -ArgumentList $filepath -PassThru
しかし、私が.batファイルでコードを実行すると、cmdウィンドウが表示され、何も操作せずに数秒で消えます。
私はCMD上の.BATファイルを実行すると、このエラーが表示されます。
の.batファイルに挿入されたコードは次のとおりです。
Add-Type -AssemblyName presentationCore
$filepath = [uri] "C:\Users\??????\Desktop\small.mp4"
$wmplayer = New-Object System.Windows.Media.MediaPlayer
$wmplayer.Open($filepath)
Start-Sleep 2 # This allows the $wmplayer time to load the audio file
$duration = $wmplayer.NaturalDuration.TimeSpan.TotalSeconds
$wmplayer.Play()
Start-Sleep $duration
$wmplayer.Stop()
$wmplayer.Close()
あなたならば、私が最も感謝するでしょうこの問題を解決するのに役立ちます。
ありがとうございました。
「コードを挿入する」とはどういう意味ですか?また、あなたの "start playing"行は、おそらく最初に#を持つことを意図しています。 –
私はすでに投稿を修正しました。私は.batファイルを参照していました –
おそらく実行ポリシーのためですか? PowerShellウィンドウでget-executionpolicyを実行し、結果を共有する –