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










1














I did try this test.reg



Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudio]@="chunk audio (5 min)""Icon"="%SystemRoot%\System32\shell32.dll,186"

[HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudioCommand]@="%SystemRoot%system32WindowsPowerShellv1.0powershell.exe C:UsersMeDesktop5min_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 ....shellChunkAudioCommand in the registry. (I tried to manualy add the %SystemRoot%system32... C:...audio.ps1 %1)



I also tried:



[HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudioCommand]
@="CMD.EXE /C Powershell.exe -File C:\Users\MeDesktop\petit_program\PowerShell\PowerShell_script\5min_chunk_audio.ps1 %1"









share|improve this question


























    1














    I did try this test.reg



    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudio]@="chunk audio (5 min)""Icon"="%SystemRoot%\System32\shell32.dll,186"

    [HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudioCommand]@="%SystemRoot%system32WindowsPowerShellv1.0powershell.exe C:UsersMeDesktop5min_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 ....shellChunkAudioCommand in the registry. (I tried to manualy add the %SystemRoot%system32... C:...audio.ps1 %1)



    I also tried:



    [HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudioCommand]
    @="CMD.EXE /C Powershell.exe -File C:\Users\MeDesktop\petit_program\PowerShell\PowerShell_script\5min_chunk_audio.ps1 %1"









    share|improve this question
























      1












      1








      1







      I did try this test.reg



      Windows Registry Editor Version 5.00

      [HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudio]@="chunk audio (5 min)""Icon"="%SystemRoot%\System32\shell32.dll,186"

      [HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudioCommand]@="%SystemRoot%system32WindowsPowerShellv1.0powershell.exe C:UsersMeDesktop5min_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 ....shellChunkAudioCommand in the registry. (I tried to manualy add the %SystemRoot%system32... C:...audio.ps1 %1)



      I also tried:



      [HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudioCommand]
      @="CMD.EXE /C Powershell.exe -File C:\Users\MeDesktop\petit_program\PowerShell\PowerShell_script\5min_chunk_audio.ps1 %1"









      share|improve this question













      I did try this test.reg



      Windows Registry Editor Version 5.00

      [HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudio]@="chunk audio (5 min)""Icon"="%SystemRoot%\System32\shell32.dll,186"

      [HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudioCommand]@="%SystemRoot%system32WindowsPowerShellv1.0powershell.exe C:UsersMeDesktop5min_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 ....shellChunkAudioCommand in the registry. (I tried to manualy add the %SystemRoot%system32... C:...audio.ps1 %1)



      I also tried:



      [HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudioCommand]
      @="CMD.EXE /C Powershell.exe -File C:\Users\MeDesktop\petit_program\PowerShell\PowerShell_script\5min_chunk_audio.ps1 %1"






      windows-10 powershell script windows-registry context-menu






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      J. Does

      1406




      1406




















          2 Answers
          2






          active

          oldest

          votes


















          1














          Try to formulate the command like this:



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





          share|improve this answer




















          • It works, but it's weird that to run the powershell you need first to run the cmd to launch it (if i understand your code correctly)
            – J. Does
            yesterday










          • And is there a way to run it silently on the background? (Without the cmd windows?)
            – J. Does
            yesterday






          • 1




            You may try it without CMD and it might even work. But with CMD you can also use this answer.
            – harrymc
            yesterday










          • if you get an error Cannot process argument because the value of argument "name" is not valid. Change the value of the "name" etc. it's because of the space isinde the selected file name.
            – J. Does
            yesterday










          • by the way it also works without the CMD.EXE /C (and re-by the way: use /k instead if you want the cmd windows to stay open)
            – J. Does
            23 hours ago


















          0














          To complete harrymc's answer:



          Windows Registry Editor Version 5.00

          ; set the name + icon in the context menu
          [HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudio]
          @="chunk audio"
          "Icon"="%SystemRoot%\System32\shell32.dll,117"

          ; run the script
          [HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudioCommand]
          @="CMD.EXE /K Powershell.exe -File C:\Users\Me\Desktop\5min_chunk_audio.ps1 "%1""


          ● CMD.EXE /C Carries out the command specified by string and then terminates



          CMD.EXE /K Carries out the command specified by string but remains (good to debug)



          type cmd /? in a cmd windows to find more args.



          ● %1 is the first argument (%2 the second...). %1 contains the path of the file. We need to quote the arg to use it (otherwhise the path will be cut at the first space). But "%1" won't work because we need to escape the quote, so we write "%1".




          Bonus:
          To get the arg (the path) on your script simply use $arg (it's an "Automatic Variables". To know more run: Get-Help about_Automatic_Variables)






          share|improve this answer




















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "3"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1388092%2fhow-to-run-a-poweshell-script-from-the-context-menu-on-audio-file%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Try to formulate the command like this:



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





            share|improve this answer




















            • It works, but it's weird that to run the powershell you need first to run the cmd to launch it (if i understand your code correctly)
              – J. Does
              yesterday










            • And is there a way to run it silently on the background? (Without the cmd windows?)
              – J. Does
              yesterday






            • 1




              You may try it without CMD and it might even work. But with CMD you can also use this answer.
              – harrymc
              yesterday










            • if you get an error Cannot process argument because the value of argument "name" is not valid. Change the value of the "name" etc. it's because of the space isinde the selected file name.
              – J. Does
              yesterday










            • by the way it also works without the CMD.EXE /C (and re-by the way: use /k instead if you want the cmd windows to stay open)
              – J. Does
              23 hours ago















            1














            Try to formulate the command like this:



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





            share|improve this answer




















            • It works, but it's weird that to run the powershell you need first to run the cmd to launch it (if i understand your code correctly)
              – J. Does
              yesterday










            • And is there a way to run it silently on the background? (Without the cmd windows?)
              – J. Does
              yesterday






            • 1




              You may try it without CMD and it might even work. But with CMD you can also use this answer.
              – harrymc
              yesterday










            • if you get an error Cannot process argument because the value of argument "name" is not valid. Change the value of the "name" etc. it's because of the space isinde the selected file name.
              – J. Does
              yesterday










            • by the way it also works without the CMD.EXE /C (and re-by the way: use /k instead if you want the cmd windows to stay open)
              – J. Does
              23 hours ago













            1












            1








            1






            Try to formulate the command like this:



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





            share|improve this answer












            Try to formulate the command like this:



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






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered yesterday









            harrymc

            253k12259562




            253k12259562











            • It works, but it's weird that to run the powershell you need first to run the cmd to launch it (if i understand your code correctly)
              – J. Does
              yesterday










            • And is there a way to run it silently on the background? (Without the cmd windows?)
              – J. Does
              yesterday






            • 1




              You may try it without CMD and it might even work. But with CMD you can also use this answer.
              – harrymc
              yesterday










            • if you get an error Cannot process argument because the value of argument "name" is not valid. Change the value of the "name" etc. it's because of the space isinde the selected file name.
              – J. Does
              yesterday










            • by the way it also works without the CMD.EXE /C (and re-by the way: use /k instead if you want the cmd windows to stay open)
              – J. Does
              23 hours ago
















            • It works, but it's weird that to run the powershell you need first to run the cmd to launch it (if i understand your code correctly)
              – J. Does
              yesterday










            • And is there a way to run it silently on the background? (Without the cmd windows?)
              – J. Does
              yesterday






            • 1




              You may try it without CMD and it might even work. But with CMD you can also use this answer.
              – harrymc
              yesterday










            • if you get an error Cannot process argument because the value of argument "name" is not valid. Change the value of the "name" etc. it's because of the space isinde the selected file name.
              – J. Does
              yesterday










            • by the way it also works without the CMD.EXE /C (and re-by the way: use /k instead if you want the cmd windows to stay open)
              – J. Does
              23 hours ago















            It works, but it's weird that to run the powershell you need first to run the cmd to launch it (if i understand your code correctly)
            – J. Does
            yesterday




            It works, but it's weird that to run the powershell you need first to run the cmd to launch it (if i understand your code correctly)
            – J. Does
            yesterday












            And is there a way to run it silently on the background? (Without the cmd windows?)
            – J. Does
            yesterday




            And is there a way to run it silently on the background? (Without the cmd windows?)
            – J. Does
            yesterday




            1




            1




            You may try it without CMD and it might even work. But with CMD you can also use this answer.
            – harrymc
            yesterday




            You may try it without CMD and it might even work. But with CMD you can also use this answer.
            – harrymc
            yesterday












            if you get an error Cannot process argument because the value of argument "name" is not valid. Change the value of the "name" etc. it's because of the space isinde the selected file name.
            – J. Does
            yesterday




            if you get an error Cannot process argument because the value of argument "name" is not valid. Change the value of the "name" etc. it's because of the space isinde the selected file name.
            – J. Does
            yesterday












            by the way it also works without the CMD.EXE /C (and re-by the way: use /k instead if you want the cmd windows to stay open)
            – J. Does
            23 hours ago




            by the way it also works without the CMD.EXE /C (and re-by the way: use /k instead if you want the cmd windows to stay open)
            – J. Does
            23 hours ago













            0














            To complete harrymc's answer:



            Windows Registry Editor Version 5.00

            ; set the name + icon in the context menu
            [HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudio]
            @="chunk audio"
            "Icon"="%SystemRoot%\System32\shell32.dll,117"

            ; run the script
            [HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudioCommand]
            @="CMD.EXE /K Powershell.exe -File C:\Users\Me\Desktop\5min_chunk_audio.ps1 "%1""


            ● CMD.EXE /C Carries out the command specified by string and then terminates



            CMD.EXE /K Carries out the command specified by string but remains (good to debug)



            type cmd /? in a cmd windows to find more args.



            ● %1 is the first argument (%2 the second...). %1 contains the path of the file. We need to quote the arg to use it (otherwhise the path will be cut at the first space). But "%1" won't work because we need to escape the quote, so we write "%1".




            Bonus:
            To get the arg (the path) on your script simply use $arg (it's an "Automatic Variables". To know more run: Get-Help about_Automatic_Variables)






            share|improve this answer

























              0














              To complete harrymc's answer:



              Windows Registry Editor Version 5.00

              ; set the name + icon in the context menu
              [HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudio]
              @="chunk audio"
              "Icon"="%SystemRoot%\System32\shell32.dll,117"

              ; run the script
              [HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudioCommand]
              @="CMD.EXE /K Powershell.exe -File C:\Users\Me\Desktop\5min_chunk_audio.ps1 "%1""


              ● CMD.EXE /C Carries out the command specified by string and then terminates



              CMD.EXE /K Carries out the command specified by string but remains (good to debug)



              type cmd /? in a cmd windows to find more args.



              ● %1 is the first argument (%2 the second...). %1 contains the path of the file. We need to quote the arg to use it (otherwhise the path will be cut at the first space). But "%1" won't work because we need to escape the quote, so we write "%1".




              Bonus:
              To get the arg (the path) on your script simply use $arg (it's an "Automatic Variables". To know more run: Get-Help about_Automatic_Variables)






              share|improve this answer























                0












                0








                0






                To complete harrymc's answer:



                Windows Registry Editor Version 5.00

                ; set the name + icon in the context menu
                [HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudio]
                @="chunk audio"
                "Icon"="%SystemRoot%\System32\shell32.dll,117"

                ; run the script
                [HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudioCommand]
                @="CMD.EXE /K Powershell.exe -File C:\Users\Me\Desktop\5min_chunk_audio.ps1 "%1""


                ● CMD.EXE /C Carries out the command specified by string and then terminates



                CMD.EXE /K Carries out the command specified by string but remains (good to debug)



                type cmd /? in a cmd windows to find more args.



                ● %1 is the first argument (%2 the second...). %1 contains the path of the file. We need to quote the arg to use it (otherwhise the path will be cut at the first space). But "%1" won't work because we need to escape the quote, so we write "%1".




                Bonus:
                To get the arg (the path) on your script simply use $arg (it's an "Automatic Variables". To know more run: Get-Help about_Automatic_Variables)






                share|improve this answer












                To complete harrymc's answer:



                Windows Registry Editor Version 5.00

                ; set the name + icon in the context menu
                [HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudio]
                @="chunk audio"
                "Icon"="%SystemRoot%\System32\shell32.dll,117"

                ; run the script
                [HKEY_LOCAL_MACHINESOFTWAREClassesSystemFileAssociationsaudioshellChunkAudioCommand]
                @="CMD.EXE /K Powershell.exe -File C:\Users\Me\Desktop\5min_chunk_audio.ps1 "%1""


                ● CMD.EXE /C Carries out the command specified by string and then terminates



                CMD.EXE /K Carries out the command specified by string but remains (good to debug)



                type cmd /? in a cmd windows to find more args.



                ● %1 is the first argument (%2 the second...). %1 contains the path of the file. We need to quote the arg to use it (otherwhise the path will be cut at the first space). But "%1" won't work because we need to escape the quote, so we write "%1".




                Bonus:
                To get the arg (the path) on your script simply use $arg (it's an "Automatic Variables". To know more run: Get-Help about_Automatic_Variables)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 19 hours ago









                J. Does

                1406




                1406



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Super User!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid …


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid …


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1388092%2fhow-to-run-a-poweshell-script-from-the-context-menu-on-audio-file%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Top Tejano songwriter Luis Silva dead of heart attack at 64

                    政党

                    天津地下鉄3号線