Home > Article > Web Front-end > How to modify the registry in js
This article is mainly implemented through the related methods of the WshShell object.
The WshShell object is a built-in object of WSH (WSH is the abbreviation of Windows ing Host, a scripting language working environment embedded in the Windows operating system). It is mainly responsible for the local running of the program, processing the registry, and creating shortcuts. methods, obtain system folder information and process environment variables, etc.
The related methods of the WshShell object are shown in Table 11.1.
In this example, the RegWrite method is mainly used. This method will be introduced in detail below.
RegWrite method is used to set the specified key or value in the registry. Its syntax format is as follows:
WshShell.RegWrite strName, anyValue, [strType]
Parameter description:
l strName: used to specify the registry The key or value. If strName ends with a backslash (// in ), this method sets the key, otherwise it sets the value. The strName parameter must start with the root key name "HKEY_CURRENT_USER", "HKEY_LOCAL_MACHINE", "HKEY_CLASSES_ROOT", "HKEY_USERS", or "HKEY_CURRENT_CONFIG".
l AnyValue: The value used to specify the key or value of the registry. When strType is REG_SZ or REG_EXPAND_SZ, the RegWrite method automatically converts anyValue to a string. If strType is REG_DWORD, anyValue is converted to an integer. If strType is REG_BINARY, anyValue must be an integer.
l StrType: The data type used to specify the key or value of the registry. The data types supported by the RegWrite method are REG_SZ, REG_EXPAND_SZ, REG_DWORD and REG_BINARY. Other data types are passed as strType, RegWrite returns E_INVALIDARG.
Implementation process:
(1) Write custom functions PageSetup_del() and PageSetup_set() to realize the functions of clearing headers and footers and restoring headers and footers. The specific code is as follows:
< 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) Create an HTML tag and call the WebBrowser control. The code is as follows:
< id="WebBrowser" classid="ClSID:8856F961-340A-11D0-A96B-00C04Fd705A2" width="0" height="0"> </ >
(3) Create "Clear Header and Footer" and "Restore Header Page" "foot" hyperlink, and call the custom functions PageSetup_del() and PageSetup_set() to implement the corresponding functions. The code is as follows:
<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) Establish relevant printing hyperlinks, and call the corresponding parameters of the WebBrowser control to implement print preview, printing and other functions. The code is as follows:
<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>
Recommended related tutorials: js tutorial
The above is the detailed content of How to modify the registry in js. For more information, please follow other related articles on the PHP Chinese website!