EzeIO.UriScheme 1.1.0

dotnet add package EzeIO.UriScheme --version 1.1.0
                    
NuGet\Install-Package EzeIO.UriScheme -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EzeIO.UriScheme" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EzeIO.UriScheme" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="EzeIO.UriScheme" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EzeIO.UriScheme --version 1.1.0
                    
#r "nuget: EzeIO.UriScheme, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package EzeIO.UriScheme@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EzeIO.UriScheme&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=EzeIO.UriScheme&version=1.1.0
                    
Install as a Cake Tool

UriScheme

NuGet build

Register, update and unregister custom uri schemes (protocol handlers) in Windows, with COM support.

Once myapp is registered, opening a link such as myapp://open?id=42 (from a browser, the Run dialog or start myapp://...) launches your application with the uri as its argument.

Targets .NET Framework 4.6.2+ and .NET 8 (net8.0-windows).

Usage

Install the package, then use the namespace:

dotnet add package EzeIO.UriScheme
using Eze.IO.Application;

Register a scheme

// Per user, no admin rights needed
UriScheme.RegisterScheme("myapp", @"C:\Program Files\MyApp\myapp.exe", "My App");

// With an icon, for every user on the machine (needs admin rights)
UriScheme.RegisterScheme("myapp", @"C:\Program Files\MyApp\myapp.exe", "My App",
    icon: @"C:\Program Files\MyApp\myapp.exe", iconNumber: 0, register: RecordScheme.OnMachine);

// With custom arguments, "%1" is replaced by the uri
UriScheme.RegisterScheme("myapp", @"C:\Program Files\MyApp\myapp.exe", "My App",
    parameter: "--open \"%1\"");

The protocol can be given as myapp, myapp: or myapp://. The first call writes:

HKEY_CURRENT_USER\Software\Classes\myapp
    (Default)      = "URL:My App Protocol"
    URL Protocol   = ""
    shell\open\command
        (Default)  = "C:\Program Files\MyApp\myapp.exe" "%1"

RecordScheme.OnCurrentUser (the default) writes under HKEY_CURRENT_USER; RecordScheme.OnMachine writes under HKEY_LOCAL_MACHINE and needs the process to run as administrator.

Check, update and unregister

if (UriScheme.Exists("myapp"))
{
    UriScheme.UpdateScheme("myapp", @"D:\MyApp\myapp.exe", "My App", "\"%1\"");
    UriScheme.UnregisterScheme("myapp", "My App");
}

If an update fails part way (for example the new path doesn't exist), the previous registration is restored.

Read the uri in your application

[STAThread]
static int Main(string[] args)
{
    foreach (UriBuilder uri in UriSchemeParser.GetUriBuilders(args))
    {
        // uri.Scheme == "myapp", uri.Host == "open", uri.Query == "?id=42"
    }
    return 0;
}

COM

UriSchemeManager (ProgId Eze.IO.Application.UriSchemeManager) exposes the same operations to COM clients, such as VBScript or VBA, once the .NET Framework build is registered with regasm /codebase UriScheme.dll. Set ThrowError to false to have failures ignored instead of raised.

Set manager = CreateObject("Eze.IO.Application.UriSchemeManager")
manager.RegisterScheme "myapp", "C:\MyApp\myapp.exe", "My App", """%1"""

Errors

Exception When
FileNotFoundException The application or icon file doesn't exist
FormatException The protocol isn't a valid scheme name
ApplicationException The scheme is already registered, or is a built-in one such as http
InvalidOperationException Updating or unregistering a scheme that isn't registered
UnauthorizedAccessException No permission to write the registry, usually OnMachine without admin rights

Upgrading from 1.0

  • Schemes are now stored under the protocol (Software\Classes\myapp) instead of under the name argument, which is now only the display name. Registrations made with a name different from the protocol never worked, and need to be removed by hand.
  • DoesItExist(protocol, name) is now Exists(protocol). The old method still works but is marked obsolete.
  • The overloads that take a parameter count (int parameters) and UriSchemeBuilder.Parameters are obsolete. Windows only passes the uri as "%1", so use the overloads without a count, or pass custom arguments as a string.
  • UriSchemeBuilder no longer needs disposing; Dispose() does nothing and is kept for compatibility.

Building

dotnet build UriScheme.sln
dotnet test UriScheme.sln

The tests register temporary schemes under HKEY_CURRENT_USER and remove them afterwards, so they run on Windows only.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0-windows7.0 is compatible.  net9.0-windows was computed.  net10.0-windows was computed. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.6.2

    • No dependencies.
  • net8.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 108 10/22/2026