Registering an Application to a URL Protocol
2860 단어 application
To enable an application to handle a particular URL Protocol, you must add a new key, with the appropriate keys and values, to the registry in HKEY_CLASSES_ROOT.
The new registry key must match the protocol scheme that is being added. For instance, to add a "note:" protocol, the key added to HKEY_CLASSES_ROOT should be note. Under this new key, the Default string value should be the display name of the new protocol, and the URL Protocol string value should contain either protocol-specific information or an empty string. Also under the new key, a DefaultIcon key and a shell key should be added. The Default string value under the DefaultIcon key must be the file name to use as an icon for this new URL protocol.
Under the shell key, a key using a verb (such as open) should be added. A command key and a DDEEXEC key may also be added under the key using a verb. The values under the command and DDEEXEC keys are used to call the application.
The following example shows which registry values might be added to register a new application (Notepad.exe in this example) to handle the new URL protocol.
HKEY_CLASSES_ROOT
note
(Default) = "URL:Note Protocol"
URL Protocol
= ""
DefaultIcon
(Default) = "notepad.exe"
shell
open
command
(Default) = "C:/WINDOWS/notepad.exe" "%1"
By adding these settings to the registry, any attempts to navigate to URLs such as "note:C:/MyFile.txt" would attempt to launch Notepad to edit the file C:/MyFile.txt. However, because the URL Protocol handler passes the complete URL string to the application registered in the command, Notepad.exe would be called with the following unanticipated command line syntax:
C:/WINDOWS/notepad.exe "note:C:/MyFile.txt"
Normally, this argument format would be handled by the application that processes the request. However, because Notepad.exe cannot be changed, the protocol prefix must be trimmed from the filename before calling Notepad. The following shell command will trim the prefix from the input string, and pass the rest to Notepad.exe:
@FOR /F "tokens=1* delims=:" %%a IN ("%~1") DO start notepad.exe "%%b"
If the preceding text were saved into a batch file, C:/WINDOWS/Note.cmd for example, the following registry value would correctly launch Notepad.exe with the file specified in the URL string:
HKEY_CLASSES_ROOT
note
shell
open
command
(Default) = "C:/WINDOWS/note.cmd" "%1"
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1538297
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Pre-Query SamplesValidate the current query criteria or provide additional query criteria programmatically, just before sending the SELEC...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.