如何通过自定义URL向应用程序传递参数

0 投票
1 回答
3552 浏览
提问于 2025-04-18 10:04

我在使用Windows 7系统。
我想通过自定义的URL来传递文件名作为参数,以便打开这个文件。
我参考了这个链接:http://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx

我的Python代码是:

import os,sys
selectedFileName=(sys.argv)[1]
os.startfile(selectedFileName)

我的注册表设置是:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\cultest]
@="\"URL:cultest Protocol\""
"URL Protocol"="\"\""

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\cultest\DefaultIcon]


[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\cultest\shell]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\cultest\shell\open]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\cultest\shell\open\command]
@="\"D:\\Test\\argument\\dist\\cultest.exe\" \"%1\""

那么我应该在webbrowser/mozila/explorer中输入哪个URL呢?
我尝试过用cultest:"C:/Users/liverpool/Desktop/Hostname.txt",但是没有成功。
C:/Users/liverpool/Desktop/Hostname.txt是文件名。

enter image description here

1 个回答

1

你的注册表代码和截图不一样:一个是'cultest.exe',另一个是'curlargu.exe'。

而且你用了HKEY_LOCAL_MACHINE这个位置,而不是HKEY_CLASSES_ROOT。虽然它们指向的是同一个地方,但可能会有影响。如果cultest.exe是你提到的文件夹里的程序,那么这个注册表代码应该是可以用的。你在浏览器里的网址调用是正确的。

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\cultest]
@="URL:cultest Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\cultest\DefaultIcon]
@="D:\\Test\\argument\\dist\\cultest.exe,0"

[HKEY_CLASSES_ROOT\cultest\shell]

[HKEY_CLASSES_ROOT\cultest\shell\open]

[HKEY_CLASSES_ROOT\cultest\shell\open\command]
@="D:\\Test\\argument\\dist\\cultest.exe \"%1\""

我今天用同样的注册表文件来运行我自己的程序,结果是可以的。我注意到斜杠有一些小的不同……

撰写回答