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
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