Write to Registry with No API

By | 2002-06-01

Who says you cant write to the registry without API?
This code is fast,smooth, and refreshes the registry instantly.
This is speed at work!

Original Author: steve brigden

Assumptions

just create a ‘Reg File’ call it Reg.Reg’ for simplicity in keeping with the code.
Place it in the root dir: eg: c: eg.Reg
paste the code straight into your form and away you go.
This function is great!

API Declarations

Not Likely

Code

Function SetDwordKeyValue(Hkey As String, SubKey As String, Keyname As String, Dword As String, Value As String)
Dword = "=dword:"
A$ = "REGEDIT4" & vbCrLf & "[" & Hkey & "" & SubKey & "]" & vbCrLf & """" & Keyname & """" & Dword & Value
Open "c: eg.reg" For Output As 1'create a 'Reg file and name it: 'Reg.reg
Print #1, A$
Close #1
ret = Shell("regedit.exe /s " & "c: eg.reg", 0)
Kill "c: eg.reg"
End Function
Sub DoIt(rtn As Boolean)
'Disable/Re-enable Regedit.exe
If rtn = True Then
ret = SetDwordKeyValue("HKEY_CURRENT_USER", "SoftwareMicrosoftWindowsCurrentVersionPoliciesSystem", "DisableRegistryTools", "", "00000001")
Else
ret = SetDwordKeyValue("HKEY_CURRENT_USER", "SoftwareMicrosoftWindowsCurrentVersionPoliciesSystem", "DisableRegistryTools", "", "00000000")
End If
End Sub

Private Sub Form_Load()
'Writing to the Registry with no API's! What! No joke, It can be done!
'Changing this value to True Disables Regedit.Exe & Vice Versa.
'Comments:Steve.Brigden@Usa.Net
DoIt False
End Sub

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.