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).
Printable View
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).
REG_SZ is a constant for 0, so just change it to 4 (the value of REG_DWORD).
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
;)
Yes, but you are still using external dependancies.
Okay, thanks.
Would a REG_DWORD be a C integer (VB Long)?
Yes. Here's some more code: http://www.parksie.net/registry.zip
Thanks, the vbapi.com sample was pretty easy to modify once I figured out to replace the string buffer with a long.