でもって、作成したPowerShellスクリプトをfoobar2000から起動させようとすると上手くいかない…
powershell -file "C:\Users\arimasou16\AppData\Roaming\foobar2000\tool\ps\script.ps1" "%artist%" "%title%"
一般ユーザーとして、ローカルのスクリプトを実行するには、予め監視者権限でpowershell
を立ち上げ、Set-ExecutionPolicy RemoteSigned
をしておく必要がある。
WindowsでPowerShellスクリプトの実行セキュリティポリシーを変更する:Tech TIPS - @ITのとおり、セキュリティポリシーを変更しているのにも拘わらず…
実際、powershell
を起動してスクリプト実行、または、コマンドプロンプト、もしくは bat ファイルからスクリプトの実行ができるか、確認しても全て可能となっている。
foobar2000からpowershell -command "Get-ExecutionPolicy;pause"
を実行させて実行セキュリティポリシーを確認すると Restricted になっている。


どうもアプリ経由でPowerShellスクリプトを起動した場合は、上記変更は関係ないらしくてpowershell -ExecutionPolicy RemoteSigned -file スクリプトファイル
とセキュリティポリシーを指定した上で実行しないと駄目のようだ。
powershell -ExecutionPolicy RemoteSigned -file "C:\Users\arimasou16\AppData\Roaming\foobar2000\tool\ps\script.ps1" "%artist%" "%title%"
これで上手く実行できた。
というか驚いたのだけど、Set-ExecutionPolicy Restricted
つまりデフォルトにしても、 RemoteSigned を指定して実行できてしまうので、どういうセキュリティ設計なのか理解に苦しむ…