Link to home
Start Free TrialLog in
Avatar of Indarnav
Indarnav

asked on

change key value

vbs code to edit following key..

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer]
"ShellState"=hex:24,00,00,00,33,28,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
  01,00,00,00,12,00,00,00,00,00,00,00,22,00,00,00

after running code the above value should be

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer]
"ShellState"=hex:24,00,00,00,33,08,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
  01,00,00,00,12,00,00,00,00,00,00,00,22,00,00,00
Avatar of abel
abel
Flag of Netherlands image

The key you are referring to is of type REG_BINARY. With VBS it is generally only possible to write REG_BINARY values that are at most 4 bytes long (by using a Long) with Shell.RegWrite (http://www.geocities.com/kilian0072002/registry/vbsreg.htm).

However, you can do it through WMI using the following method (from: http://www.microsoft.com/technet/scriptcenter/resources/qanda/feb05/hey0224.mspx). Note that the array of integers are containing decimal numbers. If you hex value is 1A, the decimal will be 16+10 = 26, etc.

Const HKEY_CURRENT_USER = &H80000001
 
strComputer = "."
 
Set objRegistry = GetObject _
    ("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
 
strKeyPath = "Software"
strValueName = "BinaryTest"
arrValues = Array(1,2,3,4,5,6,7,8,9,10)    ' your data here '
 
errReturn = objRegistry.SetBinaryValue _
    (HKEY_CURRENT_USER, strKeyPath, strValueName, arrValues)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of abel
abel
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Indarnav
Indarnav

ASKER

above code is working perfect, can i use same for adding or editing any such values? in above key there are 36 values in array, can above be used if key value is more or less than 36 in similar way?
Yes. You can use any amount of values in the array. The amount of 36 is by no means a fixed amount, it can be from zero (empty array) to any length.
ok, thanks