How to Launch a Desktop App from a Web Page Using Custom URL Protocols

This guide explains how to register a custom URL protocol in Windows, create the necessary registry entries, and use HTML links or clipboard communication to securely launch a desktop application from a web page, including handling success, failure, and fallback download flows.

Tuanzi Tech Team
Tuanzi Tech Team
Tuanzi Tech Team
How to Launch a Desktop App from a Web Page Using Custom URL Protocols

Requirement Scenario

A product requirement demands that a logged‑in web page can invoke a desktop Windows executable without additional login steps, similar to Baidu Netdisk. Direct browser execution is impossible, and solutions like Electron, Node, or browser extensions are either unsuitable or costly.

Solution: Custom URL Protocol

By registering a custom URL protocol, the client can be launched via a special link. The protocol handler is added to the Windows Registry:

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\MyProjectName]
@="URL:MyProjectName Protocol Handler"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\MyProjectName\DefaultIcon]
@="G:\Install\Microsoft VS Code\Code.exe %1"
[HKEY_CLASSES_ROOT\MyProjectName\shell\open\command]
@="G:\Install\Microsoft VS Code\Code.exe %1"

Save the above as a .reg file (Unicode encoding) and double‑click to import.

After registration, a simple HTML link can launch the client:

<a href="MyProjectName://">Start Client</a>

Web‑Client Communication

To pass authentication tokens and routing information, parameters are appended to the protocol URL, e.g.:

<a href="MyProjectName://token=123&position=234" id="Btn">Start Client</a>

The client receives the string MyProjectName://token=123&position=234 and extracts the data.

Advantages : simple implementation, minimal code, hard to intercept.

Disadvantages : one‑way communication; the client must open a browser to receive parameters for two‑way interaction.

Alternative: Clipboard Listening

Both sides agree on a data format (e.g., MyProjectName://) and use the clipboard to transfer parameters. Example JavaScript using ClipboardJS:

const link = 'MyProjectName://';
const token = '123';
const position = '234';
const url = `${link}token=${token}&position=${position}`;
const clipboard = new ClipboardJS('#btn', { text: () => url });
$('#btn').click(e => { clipboard.destroy(); clipboard.onClick(e); });
clipboard.on('success', e => { console.log('url:', e.text); });

Advantages : enables bidirectional data transfer by repeatedly listening to the clipboard.

Disadvantages : requires frequent clipboard monitoring and carries a risk of data leakage.

Handling Missing Client

If the protocol is registered but the client is not installed (or the executable is removed), the browser cannot directly detect this. Approaches using ActiveX or wscript.shell are costly, have compatibility issues, and pose compliance risks.

Practical Flow (Inspired by Baidu Netdisk)

1. User clicks a download button, triggering the custom URL protocol. 2. A timer polls the server for a launch result within a short window (e.g., 10 seconds). 3. If the server confirms success, the client is considered launched. 4. If the poll times out, the UI guides the user to download and install the client, then retries the registration and launch process.

Summary

The entire process—from registering a custom URL protocol in the Windows Registry, creating launch links, handling token transmission via URL parameters or clipboard, to implementing a polling‑based fallback strategy—provides a complete solution for invoking a desktop client from a web page.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaScriptWindows RegistryClient LaunchClipboardJSURL ProtocolWeb to Desktop
Tuanzi Tech Team
Written by

Tuanzi Tech Team

Tuanzi Mobility, Ticketing & Cloud Systems – we provide mature industry solutions, share high‑quality technical insights, and warmly welcome everyone to follow and share.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.