您的位置:首页 > 编程语言 > Java开发

Java添加注册表协议

2015-08-21 16:24 169 查看

通过Java添加注册表协议,网页可以通过a标签调用,起到网页调用本地程序功能。

需要先学习如何通过添加注册表协议,实现网页调用程序

添加注册表协议的知识可以到这学习,谢谢红色石头的分享

Java代码

package cn.wonyen.registry;

import com.ice.jni.registry.NoSuchKeyException;
import com.ice.jni.registry.RegStringValue;
import com.ice.jni.registry.Registry;
import com.ice.jni.registry.RegistryException;
import com.ice.jni.registry.RegistryKey;

public class JNIRegistryHxySimu {
/**
* @param args
*/
public static void main(String[] args) {
try {
RegistryKey hxysimu = Registry.HKEY_CLASSES_ROOT.createSubKey(
"hxysimu", "");
//添加注册表协议需要有两个默认值,到网上找了没有找到实现方式,自己猜测得到的结果,希望对其他人有帮助
//设置值的时候RegStringValue构造函数第二个参数kay用空字符串就可实现给默认值赋值
hxysimu.setValue(new RegStringValue(hxysimu, "", "URL:hxysimu"));
hxysimu.setValue(new RegStringValue(hxysimu, "EditFlags", 0));
hxysimu.setValue(new RegStringValue(hxysimu, "URL Protocol",
"D:\\Program Files (x86)\\hxysimu\\uninst.exe"));
RegistryKey DefaultIcon = hxysimu.createSubKey("DefaultIcon", "");
DefaultIcon.setValue(new RegStringValue(DefaultIcon, "",
"D:\\Program Files (x86)\\hxysimu\\uninst.exe, 1"));
RegistryKey shell = hxysimu.createSubKey("shell", "");
RegistryKey open = shell.createSubKey("open", "");
RegistryKey command = open.createSubKey("command", "");
command.setValue(new RegStringValue(command, "",
"\"D:\\Program Files (x86)\\hxysimu\\uninst.exe\" %1"));
DefaultIcon.closeKey();
} catch (NoSuchKeyException e) {
e.printStackTrace();
} catch (RegistryException e) {
e.printStackTrace();
}
}
}


注册表结果截图







HTML代码

<a href="hxysimu://hello" target="_blank">模拟调用本地应用程序</a>


之前编写的.reg文件

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\hxysimu]
@="URL:hxysimu"
"EditFlags"=hex:
"URL Protocol"="D:\\Program Files (x86)\\hxysimu\\uninst.exe"

[HKEY_CLASSES_ROOT\hxysimu\DefaultIcon]
@="D:\\Program Files (x86)\\hxysimu\\uninst.exe, 1"

[HKEY_CLASSES_ROOT\hxysimu\shell]

[HKEY_CLASSES_ROOT\hxysimu\shell\open]

[HKEY_CLASSES_ROOT\hxysimu\shell\open\command]
@="\"D:\\Program Files (x86)\\hxysimu\\uninst.exe\" %1"


原创内容,转载请说明出处!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: