0

I'm trying to register a PowerShell script to run when I click on a URL in a Windows app (such as Outlook). (I want to be able to open URLs in different browsers/apps based on different URL patterns).

I've added

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -file c:\win\bin\url-handler.ps1 "%1"

to HKEY_CLaSSES_ROOT\http\shell\open\command (replacing Google Chrome, my default).

The command works fine when in I run it from a CMD console. However, when I click a URL in Outlook, a console window opens, a red error message appears, then the console closes too quickly for me to read it.

The only error logs I can find in Event Viewer (for application PowerShell) shows

Engine state is changed from Available to Stopped. 

Details: 
NewEngineState=Stopped
PreviousEngineState=Available

SequenceNumber=10

HostName=ConsoleHost
HostVersion=2.0
HostId=7ca63c36-fcc1-4fbe-9488-dfc505a80141
EngineVersion=2.0
RunspaceId=a28185bd-f8da-4648-99aa-86066d199e04
PipelineId=
CommandName=
CommandType=
ScriptName=
CommandPath=
CommandLine=

Setting policy to Unrestricted did not solve this.

How can I track down what the error might be and how to fix it?

djb
  • 4,930
  • 1
  • 34
  • 37
  • 3
    Can you put a pause at the end of your script to keep the console open? Might put you one step closer... – Jon Sampson Apr 13 '17 at 16:41
  • 2
    http://stackoverflow.com/questions/1337229/powershell-window-disappears-before-i-can-read-the-error-message – GoldenWest Apr 13 '17 at 17:29
  • Then you will be able to read the error – GoldenWest Apr 13 '17 at 17:29
  • I had tried a pause, or simpler things such as just creating a file, but Powershell never even starts running my script. I'm not even sure if powershell.exe is actually launched. – djb Apr 14 '17 at 16:46

1 Answers1

1

add -noexit to your command line to prevent that the PowerShell console immediately closes.

iRon
  • 20,463
  • 10
  • 53
  • 79
  • Thank you @iRon! With this, I was able to view the error, File U:\win\bin\url-handler.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details. With that, I should be able to solve my problem via http://stackoverflow.com/questions/4037939/powershell-says-execution-of-scripts-is-disabled-on-this-system – djb Apr 19 '17 at 14:03