Search code examples
powershellwindows-runtimeregistrywinjs

WinRT LaunchUriAsync to start a protocol which starts PowerShell


In my WinJS application I'm trying to use Windows.System.launchUriAsync() to start a protocol I have registered in the Windows registry.

This protocol then launches a PowerShell command line.

It looks like this:

var uri = new Windows.Foundation.Uri("s3update://FooBarApp");
Windows.System.Launcher.launchUriAsync(uri);

And the registry is:

Capture of registry

Calling this protocol from command line works fine. Calling it through launchUriAsync() doesn't work. I get a success callback with the sole argument being 'false', which according to the documentation might be related to the security restriction. No error, nothing in the Windows events directory.

I tried to create a little executable that in turn starts the PowerShell command line. When I modify the protocol to start this executable instead of starting directly PowerShell. It works from command line as well as from my WinJS app. That's a possible solution for my problem but I really wish I knew at least why the association of launchUriAsync with a protocol starting PowerShell does not work.


Solution

  • For system binaries the default security policy is to block access to uri schemes via the launcher URI. System binaries that are safe have been opted into supporting this using an EditFlags value of FTA_SafeForElevation

    Powershell can be quite dangerous, so if you intend to opt in your uri scheme registration do a careful security analysis first.