Windows – How to run a poweshell script from the context menu (on audio file)

context menupowershellscriptwindows 10windows-registry

I did try this test.reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\SystemFileAssociations\audio\shell\ChunkAudio]@="chunk audio (5 min)""Icon"="%SystemRoot%\\System32\\shell32.dll,186"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\SystemFileAssociations\audio\shell\ChunkAudio\Command]@="%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe C:\Users\Me\Desktop\5min_chunk_audio.ps1 %1"

It adds a context menu on the audio files as expected, but it sends an error when I click on it:

Windows cannot access the specified device, path, or file. You may not
have the appropriate permissions to access the item.

It might be because the test.reg doesn't add anything to the field "Data" in ….shell\ChunkAudio\Command in the registry. (I tried to manualy add the %SystemRoot%\system32\... C:\...audio.ps1 %1)

I also tried:

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\SystemFileAssociations\audio\shell\ChunkAudio\Command]
@="CMD.EXE /C Powershell.exe -File C:\\Users\\Me\Desktop\\petit_program\\PowerShell\\PowerShell_script\\5min_chunk_audio.ps1 %1"

Best Answer

Try to formulate the command like this:

@="CMD.EXE /C Powershell.exe -File C:\\Users\\Me\\Desktop\\5min_chunk_audio.ps1 %1"