0

I need to set default application for any powershell files as C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe using a powershell script. For that purpose I have written the following code -

cmd.exe /c assoc .ps1=
cmd.exe /c ftype myext="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
cmd.exe /c assoc .ps1=myext

Now, when I double click any .ps1 files, it opens a blank powershell window.

Can anyone please help me regarding this ?

Thanks!

Srijani Ghosh
  • 3,935
  • 7
  • 37
  • 68
  • `ftype myext="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe ""-File %1"""` – Mathias R. Jessen May 10 '17 at 09:27
  • 2
    Although having script files execute by default is a pretty terrible idea – Mathias R. Jessen May 10 '17 at 09:27
  • Thank for the suggestion. This code is not throwing any error, but it is opening the .ps1 file in notepad.exe by default. When I check with assoc command it is showing .ps1=myext . – Srijani Ghosh May 10 '17 at 09:52
  • Have a look at [this](http://stackoverflow.com/a/10137504/608772) answer. – JPBlanc May 10 '17 at 10:52
  • Changing default value for "HKCR:\Microsoft.PowerShellScript.1\Shell\Open\Command" to '"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -noLogo -ExecutionPolicy unrestricted -file "%1"' did the trick. Thanks All! – Srijani Ghosh May 11 '17 at 10:15

0 Answers0