Vbs (with Wmi) registry operations

Source: Internet
Author: User
Tags delete key

'1. The Registry reads, writes, and deletes data. Note the differences between primary keys and key values. If it is a primary key, a backslash is added behind the strname, and the key value is not required.
Dim wshshell, bkey
Set wshshell = wscript. Createobject ("wscript. Shell ")
'Write key, the value type behind can be automatically converted
Wshshell. regwrite "hkcu/software/Acme/fortuneteller/", 0
'Write Value
Wshshell. regwrite "hkcu/software/Acme/fortuneteller/Sub", 21312, "REG_DWORD"
'Regread note parameters must be enclosed in brackets
Wscript. Echo wshshell. regread ("hkcu/software/Acme/fortuneteller/Sub ")
'If you want to create a key without data or data types, you can create a sub-key and then delete the sub-key.
'But there is another problem. What if the key already exists? In this case, we need to traverse and save
'So the better method is to use the createkey of the following WMI
Wshshell. regdelete ("hkcu/software/Acme/fortuneteller/Sub ")

'2. Use the WMI Method
Const HKEY_CURRENT_USER = & h80000001
'Const hkey_current_machine = & h80000002
Set objregistry = GetObject ("winmgmts: //./root/Default: stdregprov ")
Strkeypath = "software/Acme/fortuneteller/Sub"
'Decimal Array
Arrvalues = array (0,144,232,149,164, 83)

'Because the registry was not re-opened at the beginning to check the value

'Strkeypath does not exist, and set is not successful (in fact, strkeypath also exists), return = 0 and err. Number = 0

'So it's safe to call addkey first
'Determine whether to perform the next operation based on the returned value.
Return = objregistry. createkey (HKEY_CURRENT_USER, strkeypath)
If (return = 0) and (ERR. Number = 0) then
Wscript. Echo "key added successfully"
Return = objregistry. setbinaryvalue (HKEY_CURRENT_USER, strkeypath, "cache", arrvalues)
If (return = 0) and (ERR. Number = 0) then
Wscript. Echo "value set successfully"
Else
Wscript. Echo "createkey failed. Error =" & Return
End if
Else
Wscript. Echo "createkey failed. Error =" & err. Number
End if

'strvalue = "personal folder"
'objregistry. setstringvalue HKEY_CURRENT_USER, strkeypath, "_ labelfromreg", strvalue
'Write DWORD:
'objregistry. setdwordvalue HKEY_CURRENT_USER, strkeypath, strvaluename, dwvalue
'delete key value:
'objregistry. deletevalue HKEY_CURRENT_USER, strkeypath, strvaluename
'Delete the primary key:
'objregistry. deletekey HKEY_CURRENT_USER, strkeypath

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.