url protocol启动本地exe,C#和Java都可以

注册表注册文件:新建记事本,后缀改为reg 

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Webshell]
@="WebshellProtocol"
"URL Protocol"="D:\\HX\\exe4j\\print\\print.exe"  //关键的地址,不填不能启动
[HKEY_CLASSES_ROOT\WebStorm2018.3\DefaultIcon]
@=" D:\\HX\\exe4j\\print\\print.exe,0"
[HKEY_CLASSES_ROOT\Webshell\shell]

[HKEY_CLASSES_ROOT\Webshell\shell\open]

[HKEY_CLASSES_ROOT\Webshell\shell\open\command]
@="\"D:\\HX\\exe4j\\print\\print.exe\" \"%1\""  //%1代表参数

web端:

Webshell://hello为参数,程序启动时需要截取

<a href="Webshell://hello" >UrlProtocol打印</a>

java代码:和C#类似,传参启动

public class PrintTest {
    public PrintTest() {
    }

    public static void main(String[] args) {
        try {
            char i;
            if (args.length > 0) {
                System.out.println("参数启动:" + args[0]);
                i = (char)System.in.read();
                System.out.println("your char is :" + i);
            } else {
                System.out.println("无参数参数启动");
                i = (char)System.in.read();
                System.out.println("your char is :" + i);
            }
        } catch (Exception var2) {
            ;
        }

    }
}
发布了49 篇原创文章 · 获赞 47 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/z2516305651/article/details/90666286