Famous WSH heard? He is the short form of the Windows Script Host, WSH is a Windows platform scripting command, his function is very powerful, and he was using the grammatical structure is simple, easy to use and powerful JScript and VBScript scripting language to achieve its superior functionality

In addition to the described in this article to modify the registry, he was also able to access the Excel document, but also to communicate and network, of course, his biggest advantage he can communicate and operating system, and modify the registry but he and the operating system to communicate with The tip of the iceberg. He has so many strengths and practicality, is much a lot of Windows users of all ages, in this article, I will introduce one or two, give you a taste of what WSH style.

WSH program document, written in VBScript extension. Vbs, the script program window interface by wscript.exe document interpreted in the character interface the cscript.exe document to explain the implementation of the command format: cscript filename. vbs


Dim OperationRegistry

Create objects using VBScript to modify the registry, you must first create an operating system to communicate object, the object of various methods operate on the registry, create the object and the format is as follows:


Set OperationRegistry = WScript.CreateObject (“WScript.Shell”)
The code to create a communication and operating system objects OperationRegistry

Object With this object, does not mean you can immediately operate the registry, we must also understand several important method of operation of the object to the registry.


The registry read operation RegRead
(2) the write operation to the registry RegWrite
3. The registry delete operation RegDelete of
Add a little the WSH more two general methods:
WScript.Echo () is used to display a string of text information is equivalent the MsgBox (in the VB).
WScript.Quit () is used to exit the VBScript code.

Method parameters for the above three operating RegRead, RegWrite, RegDelete need with no arguments, and the number of parameters of these operations and form is not the same, I put them together and essential parameters to talk about :
This parameter can be called “path argument”, he includes the path and values ​​of the root keys, primary keys, various sections as follows:


Root key:

Root key has two representations.
Method 1: with his string in the registry, such as:
HKEY_CLASSES_ROOT, HKEY_CURRENT_USER method: four-letter abbreviations used to represent the first two HK, after two root key is the first letter of the word. Such as:
Expressed as the root key HKEY_CLASSES_ROOT: the HKCR root key HKEY_CURRENT_USER can be expressed as: HKCU et al.

Primary key path:
The primary key path is the location of the target key of the primary key in the registry, among the primary key “” delimited opened. Such as: SoftwareMicrosoftWindowsCurrentVersionPolicies “
Key:
The key parameters directly connected to the primary key after the path. An example of a complete path is as follows:
“HKCRSoftwareMicrosoftWindowsCurrentVersionPoliciesNoRun”

Detailed methods


1, RegRead operating Detailed read operation RegRead is used to read the default value of the primary key in the registry or key-value data, we are able to read the data sent to the corresponding variable, and then use VB’s MsgBox () function and the data is displayed, which achieve the purpose of reading the registry data (also able to use the method of object OperationRegistry the Popup () will read the data sent to the screen), for example:


‘Read.vbs (the following code to save the read.vbs document)
Dim OperationRegistry
Set OperationRegistry = WScript.CreateObject (“WScript.Shell”)
Dim Read_Data1, Read_Data2
Read_Data1 = OperationRegistry.RegRead (“HKCR.xxf”)
‘Read under the root key HKEY_CLASSES_ROOT. XXF main key default values, and the data is sent to the variable Read_Data1
Read_Data2 = OperationRegistry.RegRead (“HKCR.xxfvalue”)
‘Read under XXF main key value key data, and the data is sent to the variable Read_Data2
MsgBox (“Default =” & Read_Data1 & “value =” & Read_Data2)
‘Will display the data read


2, RegWrite operation, Detailed Explanation write operation RegWrite is mainly used to create a new key or value in the registry, and you want to give to them an initial value, the same registry data modifications to the existing primary key or key write operation parameter structure than the read operation complicated, not only to the path parameter, but also an initial value and type of parameters.


The first look at the initial value of the parameter, this parameter is essential for the write operation, he was able to empty (null) but it can not be dispensed with. Create a new primary key, the initial value of the parameter is assigned to the default value of the primary key in the new key, the initial value of the parameters has become a new key initial data type of the initial value is determined by the type parameter there are three main types:


(1) REG_SZ: character of this type is the default type.
(2) REG_DWORD: double-byte type.
(3) REG_BINARY: binary type.


More than three types of the # 1 and # 2 with most the first three types Alternate # 2 be, in some situations, these three types of assignment method is as follows:
REG_SZ type: directly given string, such as “text”, “string” of type REG_DWORD and REG_BINARY type two assignment
i) directly with a decimal number, such as: 0,1.
ii) by hexadecimal numbers, such as: 0×12, 0xff, 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
‘Under the root key HKEY_CLASSES_ROOT new primary key. XXF and set its default value is null
OperationRegistry.RegWrite “HKCR.xxf”, “xxffile”
‘New primary key in root key under HKEY_CLASSES_ROOT. XXF and set the default value of “xxffile

OperationRegistry.RegWrite “HKCR.xxfvalue1”, “string”
‘Create a new string key value value1, and set the primary key. XXF under its initial value is “string”

OperationRegistry.RegWrite “HKCR.xxfvalue2”, 1, “REG_DWORD”
‘Primary key. Xxf under the new a REG_DWORD key value2, and set its initial value of 1

OperationRegistry.RegWrite “HKCR.xxfvalue3”, 0Xff, “REG_BINARY”
‘Xxf a binary key under the new value3, and set its initial value in hexadecimal FF in the primary key.

3, RegDelete operation Detailed the deletion RegDelete is used to remove the registry key or value, the operation is an extremely dangerous operation, he can key or value in the registry mercilessly ” cut “, regardless of the key below how important data, he can pass unimpeded use the caution.
Parameters in the form of the delete operation parameters in the form and read operations are almost identical, but there is little distinction between, that is, the delete operation without the return value given to a variable, for example:
‘Delete.vbs


Dim OperationRegistry


Set OperationRegistry = WScript.CreateObject (“WScript.Shell”)
OperationRegistry.RegRead (“HKCR.xxfvalue”)
‘Delete XXF the primary key value under the key
OperationRegistry.RegRead (“HKCR.xxf”)
‘Delete the root key under HKEY_CLASSES_ROOT. XXF primary key to emphasize that, do not change the key or value already exists in the registry, not to delete them, because improper write operations to the registry, or delete operation, in serious cases will cause the system to crash if you really want to do this, then you have made your backup of the registry.

Application Examples
1 Reading “computer name”
‘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, the transformation of the “Start” menu
‘ChangeStartMenu.vbs
Dim ChangeStartMenu
Set ChangeStartMenu = WScript.CreateObject (“WScript.Shell”)
RegPath = “HKCRSoftwareMicrosoftWindowsCurrentVersionPolicies”
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,) ‘disable the “Start” menu in the “Run”
Call Change (StartMenu_Find,) ‘”Start” menu in the “Find” function is disabled
Call Change (StartMenu_Close,) ‘disable the “Start” menu in the “shut down the system”
Add to Windows since the launch of the program, the program can be run automatically at boot time.
‘AddAutoRunProgram.vbs
‘Assuming that the program in the c: myfile document in the folder, the document called 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 self-starting the program the full path to the document name
AutoRunProgram.Write RegPath & Key_Name, Key_Data, Type_Name
‘Add in the Startup group since the launch of the program autorun.exe
MsgBox (“Success!”)


Original title: VBScript to modify the Windows registry – QQ exchange group: 90991311
Original URL:

Related posts:

  1. Modify the Windows registry with VBScript
  2. Modify the Windows registry with VBScript
  3. Modify the Windows registry with VBScript
  4. VBS to modify the registry
  5. With Asp modify registry
  6. With Asp modify registry

This entry is filed under Uncategorized.

LEAVE A REPLY

Please enter your comment!
Please enter your name here