js如何修改注册表

互联网 20-4-5

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

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

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

本实例中主要应用了 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教程

以上就是js如何修改注册表的详细内容,更多内容请关注技术你好其它相关文章!

来源链接:
免责声明:
1.资讯内容不构成投资建议,投资者应独立决策并自行承担风险
2.本文版权归属原作所有,仅代表作者本人观点,不代表本站的观点或立场
标签: 注册表
上一篇:php获取远程图片并下载保存到本地的方法分析 下一篇:如何利用js计算正方形的面积

相关资讯