This content originally appeared on DEV Community and was authored by Avinash Tare
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.
#include <stdio.h>
#include <conio.h>
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
- it's open a modal to open url.
- OUTPUT:-
- Now you can parse this url and do anyting what you want.
Follow Me on GitHub Avinash Tare
This content originally appeared on DEV Community and was authored by Avinash Tare
Avinash Tare | Sciencx (2024-08-05T20:33:30+00:00) How to create own URL Protocol In Windows. Retrieved from https://www.scien.cx/2024/08/05/how-to-create-own-url-protocol-in-windows/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.