Java添加注册表协议

通过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"

原创内容,转载请说明出处!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值