使用js修改注册表的方法

发布时间:2020-04-07 11:09:18 作者:小新
来源:亿速云 阅读:89

今天小编给大家分享的是使用js修改注册表的方法,很多人都不太了解,今天小编为了让大家更加了解使用js修改注册表的方法,所以给大家总结了以下内容,一起往下看吧。一定会有所收获的哦。

使用js修改注册表的方法

本文主要通过WshShell 对象的相关方法实现。

WshShell对象是WSH(WSH是Windows ing Host的缩写,内嵌于Windows操作系统中的脚本语言工作环境)的内建对象,主要负责程序的本地运行、处理注册表、创建快捷方式、获取系统文件夹信息及处理环境变量等工作。

WshShell 对象的相关方法如表11.1所示。

使用js修改注册表的方法

本实例中主要应用了 RegWrite方法,下面将对该方法进行详细介绍。

RegWrite方法用于在注册表中设置指定的键或值,其语法格式如下:

WshShell.RegWrite strName, anyValue, [strType]

参数说明:

l     strName:用于指定注册表的键或值,若strName以一个反斜杠 (在 中为//) 结束,则该方法设置键,否则设置值。strName 参数必须以根键名“HKEY_CURRENT_USER”、 “HKEY_LOCAL_MACHINE”、“HKEY_CLASSES_ROOT”、“HKEY_USERS”或 “HKEY_CURRENT_CONFIG”开头。

l     AnyValue:用于指定注册表的键或值的值。当strType为REG_SZ或REG_EXPAND_SZ时,RegWrite方法自动将 anyValue转换为字符串。若strType为REG_DWORD,则anyValue被转换为整数。若strType为REG_BINARY,则 anyValue必须是一个整数。

l     StrType:用于指定注册表的键或值的数据类型。RegWrite方法支持的数据类型为REG_SZ、REG_EXPAND_SZ、 REG_DWORD和REG_BINARY。其他的数据类型被作为strType传递,RegWrite 返回 E_INVALIDARG。

实现过程:

(1)编写自定义 函数PageSetup_del()和PageSetup_set(),用于实现清空页眉页脚和恢复页眉页脚的功能。具体代码如下:

< language=" "> 
 var HKEY_RootPath="HKEY_CURRENT_USER//Software//Microsoft//Internet Explorer//PageSetup//"; function PageSetup_del()
{  
 //清空页眉页脚
 try
{ 
 var WSc=new ActiveX ("W .Shell");  HKEY_Key="header"; 
 WSc.RegWrite(HKEY_RootPath+HKEY_Key,"");  HKEY_Key="footer"; 
 WSc.RegWrite(HKEY_RootPath+HKEY_Key,""); 
}catch(e){} 
} 
function PageSetup_set()
{ 
 //恢复页眉页脚 
 try{ 
 var WSc=new ActiveX ("W .Shell");  HKEY_Key="header"; 
 WSc.RegWrite(HKEY_RootPath+HKEY_Key,"&w&b页码,&p/&P");  
HKEY_Key="footer"; 
 WSc.RegWrite(HKEY_RootPath+HKEY_Key,"&u&b&d"); 
 }catch(e){} 
} 
</ >

(2)建立HTML的 标签,调用WebBrowser控件,代码如下:

< id="WebBrowser" classid="ClSID:8856F961-340A-11D0-A96B-00C04Fd705A2" width="0" height="0">

</ >

(3)创建“清空页眉页脚”和“恢复页眉页脚”的超级链接,并调用自定义函数PageSetup_del()和PageSetup_set()实现相应功能。代码如下:

<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ="PageSetup_del()">清空页眉页脚</a>

<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ="PageSetup_set()"> 恢复页眉页脚 </a>

(4)建立相关的打印超级链接,并调用WebBrowser控件的相应参数实现打印预览、打印等功能。代码如下:

<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ="document.all.WebBrowser.Execwb(7,1)">打印预览</a>

 <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ="document.all.WebBrowser.Execwb(6,1)">打印</a>

 <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ="document.all.WebBrowser.Execwb(6,6)">直接打印</a>

 <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ="document.all.WebBrowser.Execwb(8,1)">页面设置</a>

关于使用js修改注册表的方法就分享到这里了,当然并不止以上和大家分析的办法,不过小编可以保证其准确性是绝对没问题的。希望以上内容可以对大家有一定的参考价值,可以学以致用。如果喜欢本篇文章,不妨把它分享出去让更多的人看到。

推荐阅读:
  1. JavaScript修改注册表的方法
  2. JS更改注册表的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

js

上一篇:phpmailer使用gmail显示could not authenticate

下一篇:实现执行一个java脚本文件的方法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》