Transfer from:
http://edu.cn700.com/
After reading this, you can use the ASP to modify the registry!
Did the famous WSH heard? It is the abbreviation form of Windows Script Host. WSH is the script directive of the Windows platform. Its features are very powerful, and it uses the syntax structure simple, easy to learn easy to use and powerful JScript and VBScript scripting language to achieve its excellent function. In addition to the modification registry introduced by this article, it can also access the Excel file, can also communicate with the network. Of course, its biggest advantage is to communicate with the operating system, and the modification of the registry is only communicated with the operating system. tip of the iceberg. It has such a lot of advantages and practicality, and is being favored by many Windows users. This article introduces you to one or two, let everyone appreciate WSH style.
The extension of the WSH program file written in VBScript is .vbs, this scriptor is executed by the window interface is performed by the WScript.exe file, and the character interface is performed by the CScript.exe file, the command format is: CScript filename. VBS
Create an object
Modify the registry with VBScript, you must first create an object that can be communicated with the operating system, and then use the object to operate the registry, and the method and format of this object is created.
DIM OperationRegistry
Set OperationRegistry = WScript.createObject ("wscript.shell")
These codes have created an object OperationRegistry with the operating system.
Object method
With this object, it is not equal to working with the registry immediately, and we must also figure out several important ways to operate on the registry.
1. Read operation registry regread
2. Write an operation of the registry RegWrite
3. Delete operation of the registry regdelete
Supplement, WSH has two universal methods:
WScript.echo () is used to display a string of text information, equivalent to Msgbox () in VB.
WScript.quit () is used to exit the VBScript program.
Parameters of the method
For the above three operations regread, regWrite, Regdelete requires parameters, and the number and form of the parameters of these operations are not the same, and I will talk about their common and indispensable parameters:
This parameter can be referred to as "path parameters", which includes root key, primary key path, and key value, and the methods represented by each part are as follows:
Root key:
The root key has two representations.
Method 1: Directly use it in the string in the registry, such as:
HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, etc.
Method 2: Use the four letters of abbreviations to indicate that the first two are HK, the next two is the first letter of the root key word. Such as:
The root key hkey_classes_root is represented as: HKCR, the root key HKEY_CURRENT_USER can be represented as: HKCU, etc.
Programs path:
The primary keypread is the primary key position of the target key in the registry, and each primary key is separated from "/". Such as: "Software / Microsoft / Windows / CurrentVersion / Policies /"
Key value:
The key value parameter is directly connected to the primary key path. For example, a complete path is as follows:
"HKCR / Software / Microsoft / Windows / Currentversion / Policies / Norun"
Method
1, regread operation details
The read operation regread is mainly used to read the default value or key value of the primary key in the registry, and we can send the read data to the corresponding variable, and then display the data from the MSGbox () function in VB. This reaches the purpose of reading data in the registration table (or method popup () can be used to send the data to the screen), for example: 'read.vbs (saving the following code as READ.VBS file) )
DIM OperationRegistry
Set OperationRegistry = WScript.createObject ("wscript.shell")
Dim read_data1, read_data2
Read_data1 = OperationRegistry.regread ("HKCR / .XXF /")
'Read the default value of the.xxf primary key under the root key hkey_classes_root, and send the data to the variable read_data1
Read_data2 = OperationRegistry.regread ("HKCR / .XXF / VALUE")
'Read the data of the value key value under the.xxf primary key and send the data to the variable read_data2
Msgbox ("default =" & read_data1 & "value =" & read_data2)
'Show the data read out
2. Reprwrite operation details
The write operation regWrite is mainly used to create a new primary key or key value in the registry, and give them an initial value, which can also modify data in the registry in the registry, and therefore write operation. The parameter structure is more complicated than the read operation. It is not only a path parameter, but also an initial value and type parameters.
Let's see the initial value parameters, this parameter is essential for writing, it can be empty, but it can't save. When the new primary key is created, the initial value parameter gives the default value of the primary key. When the key value is created, the initial value parameter has become the initial data of the new key value. The type of initial value is determined by the type parameters. There are three main types of types: types:
(1) REG_SZ: Characteristic. This type is the default type
(2) REG_DWORD: Double-byte type.
(3) REG_BINARY: binary type.
The above three types of first types and second types are used, and the third type can be replaced in certain occasions. The three types of assignment methods are as follows:
For REG_SZ type: Directly given a string, such as "text", "string", etc.
There are two types of assignments for REG_DWORD and REG_BINARY.
i) Directly represented by decimal number, such as: 0, 1, etc.
II) represents the number of hexadecimal, such as: 0x12, 0xff, etc. Example:
'Write.vbs
DIM OperationRegistry
Set OperationRegistry = WScript.createObject ("wscript.shell")
Default = OperationRegistry.regread ("HKCR /")
'Get an null value (NULL)
OperationRegistry.Regwrite "HKCR / .xxf /", Default
'Under root key hkey_classes_root, create a new primary key .xxf, and set it off the default
OperationRegistry.Regwrite "hkcr / .xxf /", "xxffile"
'Under root key hkey_classes_root, create a new primary key .xxf, and set the default value to "xxffile"
OperationRegistry.RegWrite "HKCR / .XXF / VALUE1", "String"
'Under the primary key. XXF, create a new character string key value value1, and set its initial value to "string"
OperationRegistry.Regwrite "HKCR / .XXF / VALUE2", 1, "REG_DWORD"
'Under the primary key. XXF, create a new REG_DWORD key value value2, and set its initial value of 1
OperationRegistry.Regwrite "HKCR / .XXF / VALUE3", 0xFF, "REG_BINARY"
'Enter a binary key value value3 under the primary key. XXF, and set the initial value of hexadecimal FF
3, regdelete operation details
Deleting Action Regdelete is mainly used to delete the existing primary or key values in the registry, which is an extremely dangerous operation, which can "cut off" in the registry of the primary key or key value, no matter There are more important data below this key value, which can be used in power, so be careful when using this operation.
The parameter form of the delete operation is almost identical to the parameter form of the read operation, but there is a little difference, that is, the delete operation does not need to be given to a variable, for example:
'delete.vbs
DIM OperationRegistry
Set OperationRegistry = WScript.createObject ("wscript.shell")
OperationRegistry.regread ("HKCR / .xxf / Value")
'Delete the value of the VALUE key under the .xxf primary key
OperationRegistry.regread ("hkcr / .xxf /")
'Delete the .xxf primary key under the root key hkey_classes_root
Although it is, do not change the primary key or key value existing in the registry, do not delete them, because the registry is improper write operation or deletion, the situation will cause the system to crash! If you really want to do this , Then please make a backup of the registry.
Applications
1, read this machine "computer name"
'Readcomputername.vbs
Dim Readcomputername
Set readcomputername = wscript.createObject ("wscript.shell")
DIM Computername, RegPath
RegPath = "HKLM / System / CurrentControlSet / Control / Computername / Computername / Computername"
Computername = readcomputername.regread (RegPath)
MSGBOX ("Computer Name" & Computername)
2, hidden small arrows on the shortcut icon
'Hidden.vbs
Dim Hiddenarrowicon
Set hiddenarrowicon = wscript.createObject ("wscript.shell")
Dim regpath1, regpath2
Regpath1 = "HKCR / LNKFILE / ISSHORTCUT"
Regpath2 = "HKCR / PIFFILE / ISSHORTCUT"
Hiddenarrowicon.Regdelete (regPath1)
Hiddenarrowicon.Regdelete (regPath2)
3, transform "start" menu
'ChangeStartMenu.vbs
DIM ChangeStartMenu
Set changestartMenu = wscript.createObject ("wscript.shell")
RegPath = "HKCR / Software / Microsoft / Windows / CurrentVersion / Policies /" TYPE_NAME = "REG_DWORD"
Key_Data = 1
STARTMENU_Run = "norun"
STARTMENU_FIND = "NOFIND"
STARTMENU_CLOSE = "noclose"
SUB Change (argument)
ChangeStartMenu.Regwrite Regpath & Argument, Key_Data, Type_name
Msgbox ("Success!")
End Sub
Call change (startMenu_run) Disables "Run" function in the "Start" menu
Call change (startMenu_find) 'Disables the "Find" function in the Start menu
Call change (StartMenu_Close) 'Disables the "Close System" function in the Start menu
4. Add self-starting procedures to Windows
This program can run automatically when booting.
'AddAutorunprogram.vbs
'Suppose the program is in the C: / MyFile folder, the file name is Autorun.exe
DIM Autorunprogram
Set autorunprogram = wscript.createObject ("wscript.shell")
RegPath = "HKLM / Software / Microsoft / Windows / CurrentVersion / Run /"
TYPE_NAME = "reg_sz"
Key_Name = "autorun"
Key_Data = "c: /myfile/autorun.exe"
'The full path file name of the self-starter
Autorunprogram.write regPath & key_name, key_data, type_name
'Add self-starter autorun.exe in the boot group
Msgbox ("Success!")