'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