我尝试自己查找解决方案,但是当我使用其协议的链接时,我仍然不知道如何启动我的VB.NET程序并运行子程序。 我正在寻找代码或帮助编写代码,以便自动添加自定义协议。
示例:' GN://示例'
答案 0 :(得分:1)
框架中没有任何部分可以为您完成。你需要分开问题。
首先,Windows在哪里存储该信息?
以下是Microsoft文档:
https://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx
其次,如何编写这些注册表项?
以下是.NET框架中Registry
类的链接:
https://msdn.microsoft.com/en-us/library/microsoft.win32.registry(v=vs.110).aspx
以下是有关如何将这些值写入注册表的示例:
' Creates the custom protocol and sets the description
Registry.ClassesRoot.CreateSubKey("GN", RegistryKeyPermissionCheck.ReadWriteSubTree).SetValue(String.Empty, "Custom Protocol Description")
Dim protocolSubKey = Registry.ClassesRoot.OpenSubKey("GN", True)
' Icon
' TODO : Update Executable Name
protocolSubKey.CreateSubKey("DefaultIcon").SetValue(String.Empty, "ExecutableName.exe,1")
' URL Protocol string value indicates that this key declares a custom pluggable protocol handler (stays empty)
protocolSubKey.SetValue("URL Protocol", "")
' Program to execute
Dim commandSubKey = protocolSubKey.CreateSubKey("shell").CreateSubKey("open").CreateSubKey("command")
' TODO : Update path to Executable File
commandSubKey.SetValue(string.Empty, """C:\Program Files\Alert\ExecutableName.exe\"" ""%1""")
如何处理请求的示例:
Private Shared Function ProcessInput(s As String) As String
' TODO Verify and validate the input
' string as appropriate for your application.
Return s
End Function
Private Shared Sub Main(args As String())
Console.WriteLine("ExecutableName.exe invoked with the following parameters." & vbCr & vbLf)
Console.WriteLine("Raw command-line: " & vbLf & vbTab + Environment.CommandLine)
Console.WriteLine(vbLf & vbLf & "Arguments:" & vbLf)
For Each s As String In args
Console.WriteLine(Convert.ToString(vbTab) & ProcessInput(s))
Next
Console.WriteLine(vbLf & "Press any key to continue...")
Console.ReadKey()
End Sub
将输出:
ExecutableName.exe invoked with the following parameters.
Raw command-line:
"C:\Program Files\Alert\ExecutableName.exe" "GN:"Hello World""
Arguments:
alert:Hello
World
Press any key to continue...
让它与浏览器无缝协作
我不会重复那个伟大答案中已经说过的话: