javascript调用客户端程序,js的调用方式有哪三种

本篇文章给大家谈谈javascript调用函数的方法有哪些,以及javascript调用客户端程序,希望对各位有所帮助,不要忘了收藏本站喔。

web项目中要调第三方客户端,于是归纳整理了js调用客户端exe程序的几种方法,如下:

    方法一 :  使用ActiveXObject直接执行指定路径的.exe文件 ,此方法只针对IE浏览器

<html> 
<head> 
< language="java"> 
function Run(strPath){ 
 try {
   var objShell = new ActiveXObject("w.shell"); 
   if(!objShell){
       alert('Could not get reference to WScript.Shell');
       return;
   }
     objShell.exec(strPath); 
     objShell = null; 
   }catch(errorObject){
     alert('Error:
' + errorObject.message);
   }
} 
</> 
</head> 
<body> 请输入要运行的程序路径:<br> 
<input name=exe type=text size=20 value="D:\a.doc"> 
<BUTTON class=button οnclick="Run(exe.value)">确定</BUTTON> 
</body> 
</html> 

    方法二:  通过URL Protocol实现调用本地应用程序,任何浏览器都兼容

以下转载自 : Js调用exe程序方法(通过URL Protocol实现网页调用本地应用程序)

1.使用记事本(或其他文本编辑器)创建一个protocal.reg文件,并写入以下内容
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOTWebshell]
@="URL:Webshell Protocol Handler"
"URL Protocol"=""
[HKEY_CLASSES_ROOTWebshellDefaultIcon]
@="C:\Program Files (x86)\Tencent\WeChat\WeChat.exe"
[HKEY_CLASSES_ROOTWebshellshell]
[HKEY_CLASSES_ROOTWebshellshellopen]
[HKEY_CLASSES_ROOTWebshellshellopencommand]
@=""C:\Program Files (x86)\Tencent\WeChat\WeChat.exe" "%1""
2.修改参数

使用记事本打开文件后,按照下图说明修改相关参数

2.1修改连接名称

修改红框内名称自定义即可,全部使用英文字符(该名称即为调用时的href),共六处

2.2修改可执行文件路径

修改红框内可执行文件路径,共两处

需注意:文件路径中使用//分割

3.执行protocal.reg文件
4.创建调用连接

连接地址为 步骤1中所命名的链接名称,后面加://hello,(hello为传递参数,可任意添加)

   


C#写注册表

public static void CreateRegedit(string strkey,string value)
        {
            try
            {
                RegistryKey RegKey = Registry.ClassesRoot;
                RegistryKey regkey =
                  RegKey.OpenSubKey(strkey, true);
                if (regkey == null)
                    regkey = RegKey.CreateSubKey(strkey);

                regkey.SetValue("", "URL openOffice Handler");
                regkey.SetValue("URL Protocol", "程序名称");

                RegistryKey regkeyDefaultIcon =
                 regkey.OpenSubKey("DefaultIcon", true);
                if (regkeyDefaultIcon == null)
                    regkeyDefaultIcon = regkey.CreateSubKey("DefaultIcon");

                regkeyDefaultIcon.SetValue("", Application.StartupPath + "\\程序名称.exe");

                RegistryKey regkeyShell =
               regkey.OpenSubKey("shell", true);
                if (regkeyShell == null)
                    regkeyShell = regkey.CreateSubKey("shell");
                RegistryKey regkeyopen =
             regkeyShell.OpenSubKey("open", true);
                if (regkeyopen == null)
                    regkeyopen = regkeyShell.CreateSubKey("open");

                RegistryKey regkeycommand =
            regkeyopen.OpenSubKey("command", true);
                if (regkeycommand == null)
                    regkeycommand = regkeyopen.CreateSubKey("command");
                regkeycommand.SetValue("", Application.StartupPath + "\\程序名称.exe %1");
                RegKey.Close();
                RegistryKey RegUserKey = Registry.CurrentUser;
                RegistryKey regUserkey =
                RegUserKey.OpenSubKey(strkey, true);
                if (regUserkey == null)
                    regUserkey = RegUserKey.CreateSubKey(strkey);
                RegistryKey reguserkeyDefaultIcon =
                   regUserkey.OpenSubKey("DefaultIcon", true);
                if (reguserkeyDefaultIcon == null)
                    reguserkeyDefaultIcon = regUserkey.CreateSubKey("DefaultIcon");
                reguserkeyDefaultIcon.SetValue("", Application.StartupPath + "\\程序名称.exe");
                RegUserKey.Close();
            }
            catch (Exception ex)
            {
                LogManager.WriteError("CreateRegedit", ex.StackTrace);
            }          
        }

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值