我试图使用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并共享结果 –