Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

c# - How do I create a "custom protocol" and map it to an application?

How would one go about creating a "custom protocol?" I know you can create a URL protocol by adding a number of registry entries to HKEY_CLASSES_ROOT, but that seems to only work in a browser. I need for it to work in Windows Explorer also.

I know that I can write a client/server sort of interface, but I think that is overkill for my client's needs (and budget).

Long story short...

  • A third-party application should call: tbwx:<row_id>
  • My app should load and delete a record from the database.

It sounds fairly simple (or so I thought). Any ideas?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

At least on Windows 7, you can create a custom protocol as long as you add a URL Protocol value of type REG_SZ to the key. It doesn't need an actual value, just needs to be present. Here's a simple example of an "Echo Protocol" I just created which works in explorer.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOTecho]
"URL Protocol"=""
@="Echo Protocol"

[HKEY_CLASSES_ROOTechoshell]

[HKEY_CLASSES_ROOTechoshellopen]

[HKEY_CLASSES_ROOTechoshellopencommand]
@="C:\WINDOWS\SYSTEM32\CMD.EXE /Q /C (echo %1) && pause"

I've found it will also work in the keys HKCUSoftwareClasses and HKLMSoftwareClasses too. It isn't listed in the Control PanelProgramsDefault ProgramsSet Associations list however. Other keys might need to be updated or it would have to be registered with Windows somehow.

I imagine it is the same or similar in older versions of Windows XP and up.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...