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.
2. Navigate to the Protocols Section:
- Go to HKEY_CLASSES_ROOT in the registry.
- Right-click on HKEY_CLASSES_ROOT and select New > Key.
- Name this key after your custom protocol (e.g., myapp).
3. Define the Default Value:
- Double clickon (Defualt).
- Write any thing about you protocol (e.g,. my app protocol)
- press ok.
- Create New string value.
- add value URL Protocol it's required.
- 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.
- name of the key is shell:
5. Create an open Key Inside the shell Key:
- Right-click the shell key, select New > Key, and name it open.
6. Create a command Key Inside the open Key:
- Right-click the open key, select New > Key, and name it command.
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:
- 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;
}
* 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/)
Top comments (1)
This post contains nothing about C, so why is it tagged with
#c
?