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

本实例中主要应用了 RegWrite方法,下面将对该方法进行详细介绍。
RegWrite方法用于在注册表中设置指定的键或值,其语法格式如下:
1 | 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(),用于实现清空页眉页脚和恢复页眉页脚的功能。具体代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | < 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控件,代码如下:
1 2 3 | < id= "WebBrowser" classid= "ClSID:8856F961-340A-11D0-A96B-00C04Fd705A2" width= "0" height= "0" >
</ >
|
登录后复制
(3)创建“清空页眉页脚”和“恢复页眉页脚”的超级链接,并调用自定义函数PageSetup_del()和PageSetup_set()实现相应功能。代码如下:
1 2 3 | <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控件的相应参数实现打印预览、打印等功能。代码如下:
1 2 3 4 5 6 7 | <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如何修改注册表的详细内容。更多信息请关注PHP中文网其他相关文章!