How to modify the registry in js

王林
Release: 2020-04-05 09:19:19
forward
2265 people have browsed it

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.

How to modify the registry in js

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]
Copy after login

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){} } 
Copy after login

(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"> 
Copy after login

(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:

(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:

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!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!