JS通过注册表调用本地软件启动
(关键点:所有软件安装的注册表路径是不会变化的,这个注册表路径需沟通软件商家获取或者通过自己安装在注册表中查找得到)
// 调用 注册表编辑类 方法
function run_jxpgj(){//进项票管家
/*var shell = new ActiveXObject("WScript.Shell");
var exePath = shell.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\WOW6432Node\\CLSID\\{A9F434D7-97BE-498C-97B6-AEAA77AD451E}\\LocalServer32\\");
//据注册表信息找到本地应用程序安装路径
shell.run(exePath);*/
// 上面是简易版调用软件
var regEdit = new RegEdit();
var x = regEdit.regRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\WOW6432Node\\CLSID\\{A9F434D7-97BE-498C-97B6-AEAA77AD451E}\\LocalServer32\\");
alert(x);
if(x == null || x == ""){
alert("请先下载安装软件!");
}else{
var shell = new ActiveXObject("WScript.Shell");
var exePath = shell.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\WOW6432Node\\CLSID\\{A9F434D7-97BE-498C-97B6-AEAA77AD451E}\\LocalServer32\\");
//根据注册表信息找到本地应用程序安装路径
shell.run(exePath);
}
}
////////////////注册表编辑类start//////////////////////
/**
* 注册表编辑器,封装对注册表的操作
*/
function RegEdit(){
this.shell = new ActiveXObject("WScript.Shell");
this.regRead = regRead;
this.regWrite = regWrite;
this.regDelete = regDelete;
}
/** 返回名为 strName 的注册键或值。
* @param strName 要读取的键或值。如果 strName 以反斜线 (\) 结束,本方法将返回键,而不是值
* @return 名为 strName 的注册键或值
*/
function regRead(strName){
var val = null;
try {
val = this.shell.regRead(strName);
} catch (e) {
alert(e.message);
}
return val;
}
/** 设置 strName 指定的注册键或值
* @param strName 要写的键或值的名称.如果 strName 以反斜线 (\) 结束,本方法将返回键,而不是值
* @param anyValue 要写入键或注册表值中的值
* @param strType 可选项。要保存到注册表中的值的数据类型REG_SZ、REG_EXPAND_SZ、REG_DWORD、REG_BINARY
*/
function regWrite(strName,anyValue,strType){
if(strType == null)
strType = "REG_SZ";
this.shell.regWrite(strName,anyValue,strType);
}
/** 从注册表中删除 strName 指定的键或值。
* @param strName 要删除的键或值的名字。如果 strName 以反斜线 (\) 结束,本方法将删除键,而不是值
*/
function regDelete(strName){
this.shell.regDelete(strName);
}
////////////////注册表编辑类end//////////////////////