问题
I'm making an installer for an application which has a custom URI scheme and its own file type to open with it. The application executed with a launcher.bat
, In the registry I've set the launcher.bat
to do so. It works as it should be, unless I want to register the application wit its name to be shown as opening application both in exporer and browsers instead of launcher.bat
.
The registry file that applied by the installer script is the following (it is gets generated dynamically, so don't mind the application path as well):
Windows Registry Editor Version 5.00
; ---- Add myext extension
[-HKEY_CLASSES_ROOT\.myext]
[HKEY_CLASSES_ROOT\.myext]
"content-type"="application/myext+xml"
@="myapp"
; ---- Add myapp for protocol
[-HKEY_CLASSES_ROOT\myapp]
[HKEY_CLASSES_ROOT\myapp]
@="URL:<Application Protocol>"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\myapp\DefaultIcon]
@="MyApplication.exe,1"
[HKEY_CLASSES_ROOT\myapp\shell]
@="open"
[HKEY_CLASSES_ROOT\myapp\shell\open]
@="Open with My Application"
[HKEY_CLASSES_ROOT\myapp\open\command]
@="\"C:\\Program Files (x86)\\My Application\\launcher.bat\" \"%1\""
What else should I add to the registry to do so?
回答1:
First name your type:
assoc .<ext> <anyName>
And then set the program to open:
ftype <anyName>=<application-path>
Replace all names in angle-brackets with your names:
<ext>
: the extension
<anyName>
: a name, where windows knows wich program to use, you could assoc
multiple times with different extensions
<application-path>
: the filename of the program to open it.
回答2:
After a few days of digging, I have found the solution:
The registry above assigns extension to the launcher (or any executable) to open it with, but the OS only shows the executable name as the associated program - which is fine, because It wasn't registred. This could be shown on the properties window of the file which are associated to, in exprorer, when you right click on the file and choose open with, and even in browesers when a URI scheme is registed.
To do so, the application has to be registred as well in the registry. After digging the internet, finally found on MSDN the extra registry changes that does so.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Applications\MyApplicationLauncher.bat]
FriendlyAppName = "My Application"
DefaultIcon = "<MyApplicationPath>\MyApplication.exe,1"
Note that using application names like launcher.bat
or start.bat
might cause conflicts; to prove its uniqueness, I had to rename it in the installer package to identify it.
来源:https://stackoverflow.com/questions/42483387/windows-registry-register-an-application-to-open-a-file-type