问题
I am using windows 7 I want to pass filename as argument which I want to open through custom url. I followed link http://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx
My python code is:
import os,sys
selectedFileName=(sys.argv)[1]
os.startfile(selectedFileName)
My registry setting is:
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\""
So which url I type in webbrowser/mozila/explorer. I tried with cultest:"C:/Users/liverpool/Desktop/Hostname.txt" but it didn't work C:/Users/liverpool/Desktop/Hostname.txt is the file name
回答1:
Your registry code and screenprint are not the same: 'cultest.exe' and 'curlargu.exe'.
And you have used the HKEY_LOCAL_MACHINE instead of HKEY_CLASSES_ROOT. They point to the same, but it might make a difference. If cultest.exe is your program in the mentioned folder, then this registry code should work. Your browser URL call is correct.
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\""
I used the same REG-file today for my own program and it is working. I noticed some minor differences in the slashes...
来源:https://stackoverflow.com/questions/24265292/how-to-pass-argument-through-custom-url-to-an-application