Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Vbscript write the registry?

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains the "Vbscript how to write the registry", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Vbscript how to write the registry" bar!

Usually we only need to use the first two methods, and the specific methods are as follows:

1. RegWrite (write or create new registry data)

* New child primary key

The syntax is: WshShell.RegWrite "child primary key name"

For example, we want to create a new subprimary key "HKEY_CURRENT_USERMyReg" using the following statement:

WshShell.RegWrite "HKCUMyReg"

Note: the child primary key name must end with a backslash (), if you accidentally forget to enter this (), then the method returns the key value, that is, you want to establish a key value called MyReg under HKEY_CURRENT_USER. We must pay great attention to this point!

Note that the subkey in quotation marks must begin with one of the following root key names:

HKEY_CURRENT_USER (abbreviated as HKCU), HKEY_LOCAL_MACHINE (HKLM), HKEY_CLASSES_ROOT (HKCR), HKEY_USERS and HKEY_CURRENT_CONFIG

* create a new key value under the subprimary key (or overwrite the data of the existing key value)

Syntax: WshShell.RegWrite "child primary key name key value name", "data of key value", "type of key value"

For example, if we want to create a new string key value KeyValue under the subprimary key "HKEY_CURRENT_USERMyReg" and set the data of the key value to "str", we can use the following statement:

WshShell.RegWrite "HKCUMyRegKeyValue", "str"

(note: the key value is a string value, so the declaration of "key value type" can be omitted.)

If you create a binary or DWORD value and the data is "1", you must also declare the type of key value, as follows:

WshShell.RegWrite "HKCUMyRegKeyValue", 1, "REG_BINARY"

WshShell.RegWrite "HKCUMyRegKeyValue", 1, "REG_DWORD"

Note that data with binary and DWORD values cannot be quoted, while data with string values must be in quotation marks.

2. RegDelete (delete registry data)

* Delete a subprimary key

The syntax is: WshShell.RegDelete "child primary key name"

For example, if we want to delete the subprimary key "HKEY_CURRENT_USERMyReg", we can use the following statement:

WshShell.RegDelete "HKCUMyReg"

* delete a key value of a child primary key

The syntax is: WshShell.RegDelete "child primary key name key value name"

For example, if we want to delete the key value KeyValue of the child primary key "HKEY_CURRENT_USERMyReg", we can use the following statement:

WshShell.RegDelete "HKCUMyRegKeyValue"

Similar to RegWrite, there is a "" sign to delete the sub-primary key, and no "" means to delete the key value under the sub-primary key.

In addition to the WshShell object, we must also look at the WScirpt object. The WScirpt object represents Scripting Engine, which is automatically generated as soon as you start Engine. The WScript object provides methods for creating and reading objects. To use other objects of WSH (such as WshShell objects), you must first create and read them using the relevant methods of the WScript object (CreateObject, GetObject).

The syntax for creating an object is as follows:

WScript.CreateObject (strProgID)

Where strProgID is the identification name of the object we are going to create.

For example, to use the WshShell object and its properties and methods, we first create a WshShell object with the method CreateObject of the WScript object, with the following statement:

Set WSHShell = WScript.CreateObject ("WScript.Shell")

Give me an example. As we all know, if you use run on the start menu, Windows will record your "crime" in the list box. In fact, these data are recorded in the registry HKEY_CURRENT_USERSoftwareMicrosoftWindows

Under the CurrentVersionExplorerRunMRU subkey, all we have to do is delete the subkey and then re-establish it, won't we?

Now we can write a script. Take VBS as an example, we can create a new file with notepad and enter it (the text after "/ /" is a comment, so you don't have to enter it):

/ / define the object. To edit the registry, we need to use the WSHShell object and its methods

Dim WSHShell

/ / the method CreateObject of the object to create the WSHShell object

Set WSHShell = WScript.CreateObject ("WScript.Shell")

/ / then we use the method RegDelete of the WSHShell object to delete HKEY_CURRENT_USERSoftwareMicrosoft

WindowsCurrentVersionExplorerRunMRU subkey

WSHShell.RegDelete "HKCUSoftwareMicrosoft

WindowsCurrentVersionExplorerRunMRU "

/ / finally, we restore the primary key and restore the string value "MRUList" under the primary key, setting its data to an empty string

WSHShell.RegWrite "HKCUSoftwareMicrosoft

WindowsCurrentVersionExplorerRunMRUMRUList ","

This is the end of the program, we can save the file as CleanMRU.vbs. Now we can use Scripting Engine to execute the program. Assuming that we have just saved this file in D:TEMP, we can use run on the start menu, Wcript.exe D:TEMPCleanMRU.vbs. How about a reboot? the "run" is already empty!

If we write the program so painstakingly, and finally we have to run it by hand, we might as well use the registry editor directly every time. In fact, we can make it load automatically every time it is turned on. In that case, everyone must know-- we can use the registry editor in "HKEY_LOCAL_MACHINESoftwareMicrosoftWindows"

Under the "CurrentVersionRun" subkey, create a string value of "CleanMRU" and set its data to "Wcript.exe D:TEMPCleanMRU.vbs". Hey, hey, that's it. Every time you turn it on, Windows will automatically execute the script to clear the history of "run".

Thank you for your reading, the above is the content of "how to write the registry of Vbscript". After the study of this article, I believe you have a deeper understanding of how to write the registry of Vbscript, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report