How to create your own handler for the URI scheme?

Good afternoon, there is a problem in the internal network and its sites to place links, clicking on which there is a specific action on the client side

And it is impossible to outline the URI Scheme and the context-based links use the schema to do some action on the user side

Decided to start a test for the URI to identify if clicking on which should open on the client side, the Notepad option in the form of links on a text document within a balloon network

On the web page created the following link:

<a href="notepad:\\DESKTOP-M48FDKF\\somefolder\somefile.txt">Open the txt file by notepad</a>


Then on the client side in the registry has created a new section

5e97fc972400c051109338.png

5e97fc9da0315884762056.png

And then decided to check by opening the browser and clicking this link POPs up warnings from the browser (Microsoft Edge/Chromium) that the link tries to open Notepad, and are you sure about this?
Answer Yes and get the error

Can't find file C:\Program Files (x86)\Microsoft\Edge\Application\81.0.416.53\notepad:%5C%5CDESKTOP-M48FDKF%5C%5Csomefolder%5Csomefile.txt.

You want to create a new file with the same name?


And then I realize that most likely the problem is with the path in the link to the web page, but I can not understand in what form you need to give the link

It seems the problem is that the %1 parameter stores the to URI Scheme, i.e. not the value which comes after it, and fully notepad:\\DESKTOP-M48FDKF\\somefolder\somefile.txt
Please tell me
April 19th 20 at 12:15
1 answer
April 19th 20 at 12:17
Solution
as does the execution of arbitrary programs on the link:
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Classes\runapp]
"URL Protocol"=""
@="URL:Universal run app"

[HKEY_CURRENT_USER\SOFTWARE\Classes\runapp\shell]

[HKEY_CURRENT_USER\SOFTWARE\Classes\runapp\shell\open]

[HKEY_CURRENT_USER\SOFTWARE\Classes\runapp\shell\open\command]
@="mshta EXE javascript:new(ActiveXObject)('WScript.Shell').Run(decodeURI('%1'.substr(7))),window.close()"


<a href="runapp notepad C:\\Users\\User\\Desktop\\test.txt">Open test.txt</a>


if you wish to make only a specific app opens, but it is inconvenient.
it you get the first 7 characters so cut? - Lurline_Yost3 commented on April 19th 20 at 12:20
the first 7 characters is "runapp:"
next you need to decode all sorts of %20 in standards symbols
and then launched using WScript.Shell

why mshta EXE - because he has absolute access to the system and all sorts of ActiveX API is not blocked, and there is a standard JS decodeURI, in bat(cmd) it would be fun to implement.

the only caveat is that you need double slash, as text is passed through JS and there single slashes for special characters.

But with this solution it will work even on winXP and win10 without third-party software. - donavon_Kun commented on April 19th 20 at 12:23
Hmm, it works, but not when the network wants to indicate the ball, i.e. for example \\DESKTOP-M48FDKF\\temp
When strictly locally C:\\temp - everything is OK

What could be the problem?

UPD: understood, need to \\\\\\DESKTOP-M48FDKF - Lurline_Yost3 commented on April 19th 20 at 12:26
Hmm, if you need a little more tightly, for example, uses a Protocol that only notepad will open, i.e. in your case it is universal, can be anything you want to run

but if you only need notepad, we need something like this?

<a href="notepad:\\\\DESKTOP-M48FDKF\\somefolder\\somefile.txt">Open the txt file by notepad</a>

[HKEY_CURRENT_USER\SOFTWARE\Classes\runapp\shell\open\command]
@="mshta EXE notepad javascript:new(ActiveXObject)('WScript.Shell').Run(decodeURI('%1'.substr(8))),window.close()"
- Lurline_Yost3 commented on April 19th 20 at 12:29
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Classes\notepad]
"URL Protocol"=""
@="URL:Open notepad"

[HKEY_CURRENT_USER\SOFTWARE\Classes\notepad\shell]

[HKEY_CURRENT_USER\SOFTWARE\Classes\notepad\shell\open]

[HKEY_CURRENT_USER\SOFTWARE\Classes\notepad\shell\open\command]
@="mshta EXE javascript:new(ActiveXObject)('WScript.Shell').Run('notepad '+decodeURI('%1'.substr(8))),window.close()"
- donavon_Kun commented on April 19th 20 at 12:32
mshta EXE open link javascript: to execute the script - donavon_Kun commented on April 19th 20 at 12:35

Find more questions by tags Uniform Resource Identifier