After reading this, you can use asp to modify the registry!
Have you heard of the famous WSH? It is the abbreviation of Windows Script Host. WSH is a script instruction of the Windows platform. Its function is very powerful, and it also uses JScript and VBScript scripting languages with simple syntax, easy to learn and use, and powerful functions to achieve its excellent functions. In addition to modifying the registry introduced in this article, it can also access Excel files and communicate with the network. Of course, its biggest advantage is that it can communicate with the operating system, and modifying the registry is only a way for it to communicate with the operating system. The tip of the iceberg. It is because of its many advantages and practicality that it is favored by many Windows users. This article will introduce it to you so that you can appreciate the elegance of WSH.
The extension of the WSH program file written in VBScript is .vbs. The script program is interpreted and executed by the wscript.exe file in the window interface and by the cscript.exe file in the character interface. The command format is: cscript filename. vbs
To create an object and use VBScript to modify the registry, you must first create an object that can communicate with the operating system, and then use various methods of the object to operate the registry. The method and format of creating this object are as follows:
Dim OperationRegistry
Set OperationRegistry=WScript.CreateObject("WScript.Shell")
The above code creates an object OperationRegistry that can communicate with the operating system.
Object methods Having the above object does not mean that we can immediately operate the registry. We must also understand several important methods of this object to operate the registry.
1. RegRead operation for reading the registry
2. RegWrite writing operation to the registry
3. RegDelete deletion operation on the registry
In addition, WSH also has two general methods:
WScript.Echo() is used to display a string of text information, which is equivalent to MsgBox() in VB.
Wscript.Quit() is used to exit the VBScript program.
The parameters of the method require parameters for the above three operations RegRead, RegWrite, and RegDelete, and the number and form of parameters for these operations are different. Below I will talk about one of their common and essential parameters. :
This parameter can be called a "path parameter", which includes the root key, primary key path and key value. The method of expressing each part is as follows:
Root key:
There are two ways to represent root keys.
Method 1: Directly use its string in the registry to represent it, such as:
HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, etc. Method 2: Use the four letters of the abbreviation to represent it. The first two are HK, and the last two are the first letters of the root key word. like:
The root key HKEY_CLASSES_ROOT is expressed as: HKCR, the root key HKEY_CURRENT_USER can be expressed as: HKCU, etc.
Primary key path:
The primary key path is the primary key location of the target key in the registry, and each primary key is separated by "" characters. For example: "SoftwareMicrosoftWindowsCurrentVersionPolicies"
Key value:
Key-value parameters follow the primary key path directly. For example, a complete path looks like this:
"HKCRSoftwareMicrosoftWindowsCurrentVersionPoliciesNoRun"
Detailed explanation of method
1. Detailed interpretation of the RegRead operation. The operation RegRead is mainly used to read the default value or key value data of the primary key in the registry. We can send the read data to the corresponding variable and then use the MsgBox() function in VB. Displaying the data achieves the purpose of reading the data in the registry (you can also use the method Popup() of the object OperationRegistry to send the read data to the screen), for example:
'read.vbs (save 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.xxfvalue")
'Read the data of the value key under the .xxf primary key and send the data to the variable Read_Data2
MsgBox("Default="&Read_Data1&" value="&Read_Data2)
'Display the read data
2. Detailed explanation of RegWrite operation. The write operation RegWrite is mainly used to create new primary keys or key values in the registry and give them an initial value. This operation can also modify the data of existing primary keys or key values in the registry. , so the parameter structure of the write operation is more complicated than that of the read operation. It not only requires path parameters, but also an initial value and type parameters.
Let’s look at the initial value parameter first. This parameter is essential for write operations. It can be empty (null) but cannot be omitted. When creating a new primary key, the initial value parameter is assigned to the default value of the primary key. When creating a new key value, the initial value parameter becomes the initial data of the new key value. The type of the initial value is determined by the type parameter. .There are mainly three types:
(1)REG_SZ: Character type. This type is the default type
(2)REG_DWORD: double-byte type.
(3)REG_BINARY: binary type.
The first and second types of the above three types are the most commonly used. The third type can be replaced by the second type in some situations. The assignment methods of these three types are as follows:
For REG_SZ type: directly assign with string, such as "text", "string", etc. For REG_DWORD type and REG_BINARY type, there are two assignment methods.
i) Directly expressed by decimal numbers, such as: 0, 1, etc.
ii) Expressed by hexadecimal numbers, such as: 0x12, 0xff, etc. See example:
'write.vbs
Dim OperationRegistry
Set OperationRegistry=WScript.CreateObject("WScript.Shell")
Default=OperationRegistry.RegRead("HKCR")
'Get a null value (null)
OperationRegistry.RegWrite "HKCR.xxf",Default
'Create a new primary key.xxf under the root key HKEY_CLASSES_ROOT, and set its default value to empty
OperationRegistry.RegWrite "HKCR.xxf","xxffile"
'Create a new primary key .xxf under the root key HKEY_CLASSES_ROOT and set its default value to "xxffile"
OperationRegistry.RegWrite "HKCR.xxfvalue1","string"
'Create a new string key value value1 under the primary key.xxf, and set its initial value to "string"
OperationRegistry.RegWrite "HKCR.xxfvalue2",1,"REG_DWORD"
'Create a new REG_DWORD key value value2 under the primary key.xxf, and set its initial value to 1
OperationRegistry.RegWrite "HKCR.xxfvalue3",0Xff,"REG_BINARY"
'Create a new binary key value value3 under the primary key .xxf, and set its initial value to hexadecimal ff
3. Detailed explanation of the RegDelete operation. The deletion operation RegDelete is mainly used to delete the primary key or key value that already exists in the registry. This operation is an extremely dangerous operation. It can mercilessly delete the primary key or key value in the registry. "Chop off" will work unimpeded no matter how important the data is underneath the key, 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, except for one small difference, that is, the delete operation does not need to send the return value of the operation to a certain variable, for example:
'delete.vbs
Dim OperationRegistry
Set OperationRegistry=WScript.CreateObject("WScript.Shell")
OperationRegistry.RegRead("HKCR.xxfvalue")
'Delete the value key value under the .xxf primary key
OperationRegistry.RegRead("HKCR.xxf")
'Delete the .xxf primary key under the root key HKEY_CLASSES_ROOT. It is important to emphasize that do not change the primary keys or key values that already exist in the registry, let alone delete them, because improper writing or deletion of the registry is serious. It will cause the system to crash! If you really want to do this, please make a backup of the registry.
Application examples
1. Read the "computer name" of this machine
'ReadComputerName.vbs
Dim ReadComputerName
Set ReadComputerName=WScript.CreateObject("WScript.Shell")
Dim ComputerName,RegPath
RegPath="HKLMSystemCurrentControlSetControlComputerNameComputerNameComputerName"
ComputerName=ReadComputerName.RegRead(RegPath)
MsgBox("Computer name"&ComputerName)
2. Hide the small arrow on the shortcut icon
'Hidden.vbs
Dim HiddenArrowIcon
Set HiddenArrowIcon=WScript.CreateObject("WScript.Shell")
Dim RegPath1,RegPath2
RegPath1="HKCRlnkfileIsShortCut"
RegPath2="HKCRpiffileIsShortCut"
HiddenArrowIcon.RegDelete(RegPath1)
HiddenArrowIcon.RegDelete(RegPath2)
3. Transform the “Start” menu
'ChangeStartMenu.vbs
DimChangeStartMenu
Set ChangeStartMenu=WScript.CreateObject("WScript.Shell")
RegPath="HKCRSoftwareMicrosoftWindowsCurrentVersionPolicies"
Type_Name="REG_DWORD"
Key_Data=1
StartMenu_Run="NoRun"
StartMenu_Find="NoFind"
StartMenu_Close="NoClose"
SubChange(Argument)
ChangeStartMenu.RegWrite RegPath&Argument,Key_Data,Type_Name
MsgBox("Success!")
End Sub
Call Change(StartMenu_Run) 'Disable the "Run" function in the "Start" menu
Call Change(StartMenu_Find) 'Disable the "Find" function in the "Start" menu
Call Change(StartMenu_Close) 'Disable the "Shutdown System" function in the "Start" menu
4. Add a self-starting program to Windows. This program can run automatically when the computer is turned on.
'AddAutoRunProgram.vbs
'Assume that the program is in the c:myfile folder and the file name is autorun.exe
Dim AutoRunProgram
Set AutoRunProgram=WScript.CreateObject("WScript.Shell")
RegPath="HKLMSoftwareMicrosoftWindowsCurrentVersionRun"
Type_Name="REG_SZ"
Key_Name="AutoRun"
Key_Data="C:Myfileautorun.exe"
'The full path file name of the self-starting program
AutoRunProgram.Write RegPath&Key_Name,Key_Data,Type_Name
'Add the self-starting program autorun.exe in the startup group
MsgBox("Success!")