PDA

Click to See Complete Forum and Search --> : Use REG_DWORD


JoshT
May 4th, 2001, 01:31 PM
How would I read/write a REG_DWORD from the registry? I have a value I want to toggle between 0 and 1. The sample at www.vbapi.com only deals with REG_SZ (strings).

Megatron
May 4th, 2001, 02:33 PM
REG_SZ is a constant for 0, so just change it to 4 (the value of REG_DWORD).

brijmohank
May 5th, 2001, 12:23 AM
You can write ,read ,delete REG_DWORD,REG_BINARY etc in the registry
with out any API calls ,using "WINDOWS SCRIPTING HOST"
try the following code its very simple
in aform put three command buttons and add the following code

Private Sub Command1_Click()
'WRITE INTO WINDOWS REGISTRY
'----------------------------
Dim b As Object
On Error Resume Next
Set b = CreateObject("wscript.shell")
b.RegWrite "HKCU\VBCODE.COM\Value", "HELLO WORLD"
b.RegWrite "HKCU\VBCODE.COM\Value1", 0, "REG_DWORD"
b.RegWrite "HKCU\VBCODE.COM\Value2", 0, "REG_SZ"
b.RegWrite "HKCU\VBCODE.COM\Value3", 0, "REG_BINARY"

End Sub

Private Sub Command2_Click()
'READ FROM WINDOWS REGISTRY
'.........................
Dim b As Object
On Error Resume Next
Set b = CreateObject("wscript.shell")
R = b.RegRead("HKCU\VBCODE.COM\Value")
Form1.Caption = R
End Sub

Private Sub Command3_Click()
'DELETE VALUES FROM WINDOWS REGISTRY
'-----------------------------------
Dim b As Object
On Error Resume Next
Set b = CreateObject("Wscript.Shell")
b.RegDelete "HKCU\VBCODE.COM\Value"
b.RegDelete "HKCU\VBCODE.COM\Value1"
b.RegDelete "HKCU\VBCODE.COM\Value2"
b.RegDelete "HKCU\VBCODE.COM\Value3"
End Sub

Private Sub Form_Load()
Command1.Caption = "Write"
Command2.Caption = "Read"
Command3.Caption = "Delete"
End Sub
;)

Megatron
May 5th, 2001, 12:05 PM
Yes, but you are still using external dependancies.

JoshT
May 7th, 2001, 06:06 AM
Okay, thanks.

Would a REG_DWORD be a C integer (VB Long)?

parksie
May 7th, 2001, 12:58 PM
Yes. Here's some more code: http://www.parksie.net/registry.zip

JoshT
May 7th, 2001, 01:24 PM
Thanks, the vbapi.com sample was pretty easy to modify once I figured out to replace the string buffer with a long.