Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RegCreateKey doesn't add the key registry

Status
Not open for further replies.

joazes

Programmer
Sep 18, 2003
13
BR
I'm trying to add by vb code the "System" key into Policies and it returns ERROR_SUCESS but the key wasn't put into windows register. Does someone know what was happened?

Note: My account is already have administrator rights.

*** a piece of code ***
>>> MODULE
Option Explicit

Private m_lngRetVal As Long

'Declarations required to access the windows registry
Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" _
(ByVal lngRootKey As Long, ByVal lpSubKey As String, phkResult _
As Long) As Long

Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal lngRootKey As _
Long) As Long
>>> FORM
Private Sub Command1_Click()
CreateKey HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\System"
End Sub

Public Function CreateKey(ByVal lngRootKey As Long, ByVal _
strRegKeyPath As String)
'Define variables
Dim lngKeyHandle As Long
'Create the key. If it already exist, ignore it.
m_lngRetVal = RegCreateKey(lngRootKey, strRegKeyPath, lngKeyHandle)
MsgBox lngKeyHandle
'Always close the handle in the registry. We do not want to corrupt these Files
m_lngRetVal = RegCloseKey(lngKeyHandle)
End Function
 
You are right!!! Now it is working fine.

Thanks for help me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top