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?

4
  • 3
    Can you put a pause at the end of your script to keep the console open? Might put you one step closer... Commented Apr 13, 2017 at 16:41
  • 2
    stackoverflow.com/questions/1337229/… Commented Apr 13, 2017 at 17:29
  • Then you will be able to read the error Commented Apr 13, 2017 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. Commented Apr 14, 2017 at 16:46

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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 stackoverflow.com/questions/4037939/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.