I've been trying to create a custom protocol (open_php_file://) to open local files through the browser. I've created the following registery-keys:
HKEY_CLASSES_ROOT
open_php_file
(Default) = "URL:PHPEd protocol"
URL Protocol = ""
DefaultIcon
(Default) = "phped.exe"
shell
open
command
(Default) = "C:\Program Files (x86)\NuSphere\7.0\phped.exe" "%1"
The problem is: I can't open files in my browser (example: open_php_file://c:\file.txt), and the protocol isn't listed in the windows default programms.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\openphpfile]
#="\"URL:openphpfile Protocol\""
"EditFlags"=hex:02,00,00,00
"URL Protocol"=""
[HKEY_CLASSES_ROOT\openphpfile\DefaultIcon]
#="\"C:\\Users\\ABC\\Documents\\Programs\\CB\\Chunks\\CGI.exe\",0"
[HKEY_CLASSES_ROOT\openphpfile\shell]
[HKEY_CLASSES_ROOT\openphpfile\shell\open]
[HKEY_CLASSES_ROOT\openphpfile\shell\open\command]
#="\"C:\\Users\\ABC\\Documents\\Programs\\CB\\Chunks\\CGI.exe\" -c \"%1\""
Basically the problem was with the underscores in your protocol.Once removed everything started working fine.You can change the path of executable as per your wish i.e. "C:\Program Files (x86)\NuSphere\7.0\phped.exe".
I tried openphpfile:blast and it worked quite nicely :)
EDIT:
the problem with this solution is that %1 gets replaced with
"open_php_file://[file]" instead of just "[file]". This way I need
some sort of filter that chops "open_php_file://".
put a space after openphpfile:[Space]Your_Content and change parameter to %2 you will get the expected result
[HKEY_CLASSES_ROOT\openphpfile\shell\open\command]
#="\"C:\\Users\\ABC\\Documents\\Programs\\CB\\Chunks\\CGI.exe\" -c \"%2\""
Windows always replaces %1 with the full URI that was entered. AFAIK there is no way to change that behavior.
This leaves you two options:
If you've written the program being called yourself, you can filter the URI when it is being invoked.
You could use an intermediate program that acts as a filter for the URI and then forwards the result to the actual protocol implementation. Fortunately for you, someone has already done exactly that. See 'CustomURL' on CodePlex. CustomURL is a small utility for registering custom URL protocols. For example you can associate the rdp:// protocol with Remote Desktop Client or the ssh:// protocol with Putty or another SSH client.
Related
I made a custom protocol handler following this link. The case is I need to open a link which can only be opened in IE and might contains several query parameters and should be opened in IE from our web app which is running on Chrome (this is really annoying). After many tries and fails, I managed to find the snippet to add entry to the windows registry hive and made .reg file and run:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\ie]
"URL Protocol"="\"\""
#="\"URL:IE Protocol\""
[HKEY_CURRENT_USER\Software\Classes\ie\DefaultIcon]
#="\"explorer.exe,1\""
[HKEY_CURRENT_USER\Software\Classes\ie\shell]
[HKEY_CURRENT_USER\Software\Classes\ie\shell\open]
[HKEY_CURRENT_USER\Software\Classes\ie\shell\open\command]
#="cmd /k set myvar=%1 & call set myvar=%%myvar:ie:=%% & call \"C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe\" %%myvar%% & exit /B"
It worked but the problem is if a link contains more than 1 query params, all but the first are omitted, I am sure this because of character encoding in windows command line:
e.g. some_example_url?query1=value1&query2=value2&query3=value3 is becoming some_example_url?query1=value1
I find this solution but it did not work either. How can I properly escape & character, so that it can be opened on IE with all query parameters. (as before mentioned link is triggered by web app running on Chrome)
EDIT: The code which triggers:
fileClicked(url) {
// url should be escaped with ^
const escapedUrl = url.replace(/&/gi, '^&');
const ie = document.createElement('a');
// ie: scheme => custom protocol handler
// host computer (windows) should add custom protocol to windows registry
ie.href = `ie:${escapedUrl}`;
ie.click();
}
EDIT 2
#muzafako fixed the script, just last line should be replaced like below:
#="cmd /c set url=\"%1\" & call set url=%%url:ie:=%% & call start iexplore -nosessionmerging -noframemerging %%url%%"
You don't need to decode query parameters at all. I've tried to find solution for this issue and saw this answer. Its works for me. just change command line to:
#="cmd /c set url=\"%1\" & call set url=%%url:ie:=%% & call start iexplore -nosessionmerging -noframemerging %%url%%"
I've recently learnt about folding in vim and that you can use :mkview to save the folds in a document. However, vim is trying to save views in the C:\Program Files (x86)\vim\ directory path, which needs Admin privileges to save to... as this is a corporate Win7 work machine, I need to convince vim it wants to save views elsewhere.
Is there a command I need to include in my _vimrc file to get vim to save the views elsewhere? Or another way to control this behaviour?
Set viewdir.
From :help mkview :
When [file] is omitted or is a number from 1 to 9, a name is generated and 'viewdir' prepended.
:help 'viewdir' gives:
*'viewdir'* *'vdir'*
'viewdir' 'vdir' string (default for Amiga, MS-DOS, OS/2 and Win32:
"$VIM/vimfiles/view",
for Unix: "~/.vim/view",
for Macintosh: "$VIM:vimfiles:view"
for VMS: "sys$login:vimfiles/view"
for RiscOS: "Choices:vimfiles/view")
global
{not available when compiled without the |+mksession|
feature}
Name of the directory where to store files for |:mkview|.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.
I am trying to add a Windows Context Menu item that will let me right click a file in Windows Explorer and click a button Open in Dev Server.
This will then pass the file path of the selected file to a Windows .bat file.
In my .bat file openLocalHostWebBrowser.bat so far I have this code below which wehn ran opens a new tab in my web browser with the supplied URL.
#echo off
start "webpage name" "http://someurl.com/"
So I need help. I know how to add the context menu in Windows Explorer that will run my openLocalHostWebBrowser.bat file when clicked on.
What I need help with is taking that file path that is passed and changing it by removing part of the front of it and prepending my localhost or any URL for that matter, perhaps another one for a production server.
So if the file path passed to my .bat file is like this...
E:\Server\htdocs\labs\php\testProject\test.php
then I need to somehow turn it into this...
http://localhost/labs/php/testProject/test.php
The E:\Server\htdocs\ should be replaced with http://localhost/
I believe your requirement is fixed (E:\Server\htdocs\ should be replaced with http://localhost/). If so, below may help you.
#echo off
set input=%1
Echo.Input was - %input%
set converted=%input:E:\server\htdocs\=http://localhost/%
set converted=%converted:\=/%
echo.Converted to - %converted%
Sample tested output -
D:\Scripts>repl.bat E:\Server\htdocs\labs\php\testProject\test.php
Input was - E:\Server\htdocs\labs\php\testProject\test.php
Converted to - http://localhost/labs/php/testProject/test.php
Cheers, G
I am currently trying to print a HTML file using mshtml.dll. Looking up in the registry I found for html-files, the following print-to entry:
"%systemroot%\system32\rundll32.exe"
"%systemroot%\system32\mshtml.dll",PrintHTML "%1" "%2" "%3" "%4"
Unexpectedly there are some parameters to pass to mshtml.dll, what are the parameters of mshtml.dll (numbered %1, %2, %3, %4 in this registry information)?
You found this in the printto verb of the htmlfile progid. Which runs when you drag an HTML file from Explorer and drop it on a printer shortcut. The printto verb has these arguments:
%1: the path to the HTML file
%2: the printer name
%3: the printer driver name (optional)
%4: the printer port name (optional)
Taking a dependency on an undocumented function is unwise, you can't rely on this still working in the next Windows version. Using WebBrowser.Print() is the documented way. IWebBrowser2::ExecWB() in native code.
Neither the printer's name is mandatory, in fact in the "print" verb of the htmlfile progid only one parameter is specified for the same command.
By the way: I tried to replace %2 with the printer's name (with and without quotes) but it didn't do anything different, that is, the print dialog is still there.
Tried on Windows 10 and Windows 7.
How do I register a custom protocol with Windows so that when clicking a link in an email or on a web page my application is opened and the parameters from the URL are passed to it?
Go to Start then in Find type regedit -> it should open Registry editor
Click Right Mouse on HKEY_CLASSES_ROOT then New -> Key
In the Key give the lowercase name by which you want urls to be called (in my case it will be testus://sdfsdfsdf) then Click Right Mouse on testus -> then New -> String Value and add URL Protocol without value.
Then add more entries like you did with protocol ( Right Mouse New -> Key ) and create hierarchy like testus -> shell -> open -> command and inside command change (Default) to the path where .exe you want to launch is, if you want to pass parameters to your exe then wrap path to exe in "" and add "%1" to look like: "c:\testing\test.exe" "%1"
To test if it works go to Internet Explorer (not Chrome or Firefox) and enter testus:have_you_seen_this_man this should fire your .exe (give you some prompts that you want to do this - say Yes) and pass into args testus://have_you_seen_this_man.
Here's sample console app to test:
using System;
namespace Testing
{
class Program
{
static void Main(string[] args)
{
if (args!= null && args.Length > 0)
Console.WriteLine(args[0]);
Console.ReadKey();
}
}
}
Hope this saves you some time.
The MSDN link is nice, but the security information there isn't complete. The handler registration should contain "%1", not %1. This is a security measure, because some URL sources incorrectly decode %20 before invoking your custom protocol handler.
PS. You'll get the entire URL, not just the URL parameters. But the URL might be subject to some mistreatment, besides the already mentioned %20->space conversion. It helps to be conservative in your URL syntax design. Don't throw in random // or you'll get into the mess that file:// is.
If anyone wants a .reg file for creating the association, see below:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\duck]
"URL Protocol"=""
[HKEY_CLASSES_ROOT\duck\shell]
[HKEY_CLASSES_ROOT\duck\shell\open]
[HKEY_CLASSES_ROOT\duck\shell\open\command]
#="\"C:\\Users\\duck\\source\\repos\\ConsoleApp1\\ConsoleApp1\\bin\\Debug\\net6.0\\ConsoleApp1.exe\" \"%1\""
Pasted that into notepad, the file -> save as -> duck.reg, and then run it. After running it, when you type duck://arg-here into chrome, ConsoleApp1.exe will run with "arg-here" as an argument. Double slashes are required for the path to the exe and double quotes must be escaped.
Tested and working on Windows 11 with Edge (the chrome version) and Chrome
There is an npm module for this purpose.
link :https://www.npmjs.com/package/protocol-registry
So to do this in nodejs you just need to run the code below:
First Install it
npm i protocol-registry
Then use the code below to register you entry file.
const path = require('path');
const ProtocolRegistry = require('protocol-registry');
console.log('Registering...');
// Registers the Protocol
ProtocolRegistry.register({
protocol: 'testproto', // sets protocol for your command , testproto://**
command: `node ${path.join(__dirname, './index.js')} $_URL_`, // $_URL_ will the replaces by the url used to initiate it
override: true, // Use this with caution as it will destroy all previous Registrations on this protocol
terminal: true, // Use this to run your command inside a terminal
script: false
}).then(async () => {
console.log('Successfully registered');
});
Then suppose someone opens testproto://test
then a new terminal will be launched executing :
node yourapp/index.js testproto://test
It also supports all other operating system.