我試圖使用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()
我會最想感謝你可以幫助我解決這個問題。
謝謝。
你是什麼意思「插入代碼」?此外,你的「開始玩」線可能意味着在開始時會有一個#號。 –
我已經修改了帖子,我指的是一個.bat文件 –
也許是由於執行策略?在PowerShell窗口中運行get-executionpolicy並共享結果 –