DEV Community

Cover image for How to create own URL Protocol In Windows
Avinash Tare
Avinash Tare

Posted on • Edited on

How to create own URL Protocol In Windows

Creating your own URL protocol in Windows allows you to define custom behavior when a specific protocol is used in a URL. Here's how to create one:

Steps to Create a Custom URL Protocol

1. Open the Windows Registry Editor:

* Press Win + R, type `regedit`, and hit Enter.
Enter fullscreen mode Exit fullscreen mode

open windows registry

2. Navigate to the Protocols Section:

  • Go to HKEY_CLASSES_ROOT in the registry.
  • Right-click on HKEY_CLASSES_ROOT and select New > Key.

find folder

  • Name this key after your custom protocol (e.g., myapp).

create folder

3. Define the Default Value:

  • Double clickon (Defualt).
  • Write any thing about you protocol (e.g,. my app protocol)
  • press ok.

Image description

  • Create New string value.

Image description

  • add value URL Protocol it's required.

add new value

  • Now Your app is ready you can check on google chrome but we have add .exe file corresponding to our URL.

4. Create a Shell Subkey:

  • Inside your protocol key (e.g., myapp), right-click and create a new key named shell.

create new key

  • name of the key is shell:

shell key

5. Create an open Key Inside the shell Key:

  • Right-click the shell key, select New > Key, and name it open.

open key

6. Create a command Key Inside the open Key:

  • Right-click the open key, select New > Key, and name it command.

command key

7. Define the Command to Execute:

  • Click on the command key, and in the right-hand pane, double-click the (Default) entry. Set the value to the path of the executable you want to run, followed by "\"%1\"" (including the quotes). For example:

add exe file and args

  • press ok, you protocol created successfully.

8. Creating Test Program

  • Creating a program using c to get arguments. you can use any langualge. ```c

include

include

int main(int argc, char *argv[])
{
printf("Argument: \n%s", argv[1]);

getch();
return 0;
Enter fullscreen mode Exit fullscreen mode

}


 * Convert Into Exe using `c++ myapp.c -o myapp.exe`;
 * now you add this exe into command defualt value.

## 9: Test Your Protocol
 * goto chrome and write you *myapp://hello*

![Chrome url](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sobu5lmupyk24d3olxrw.png)

 * it's open a modal to open url.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/btpf5an364vyu9fkpm4g.png)

 * OUTPUT:- 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0bg60pf6r3u1fmwbggtj.png)

 * Now you can parse this url and do anyting what you want.

Follow Me on GitHub [Avinash Tare](http://github.com/avinashtare/)
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
pauljlucas profile image
Paul J. Lucas

This post contains nothing about C, so why is it tagged with #c?