7

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.

Simon
  • 5,464
  • 6
  • 49
  • 85
  • 1
    http://stackoverflow.com/questions/80650/how-do-i-register-a-custom-url-protocol-in-windows?rq=1 – Pavel Radzivilovsky Jul 30 '12 at 01:00
  • 1
    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://". – Simon Jul 30 '12 at 06:48

2 Answers2

9
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\""
perilbrain
  • 7,961
  • 2
  • 27
  • 35
  • 1
    It works without adding the `EditFlags` value and `DefaultIcon` key, interesting. Thanks for this, using on Win7. – Blagoh Mar 10 '15 at 18:01
  • @perilbrain This solution works fine on windows 7 but not on windows 10, can you suggest something for windows 10. – Madhur Sodhi Feb 28 '17 at 08:37
  • This is exactly what I'm looking for but as @MadhurSodhi mentioned, this method doesn't work on Windows 10. That would be super useful, completely eliminating the need of a "middleware" for the argument parsing. – Pedro Henrique Jul 10 '19 at 05:44
0

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:

  1. If you've written the program being called yourself, you can filter the URI when it is being invoked.
  2. 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.
djf
  • 6,592
  • 6
  • 44
  • 62