crewaustin66
Board Regular
- Joined
- Jun 11, 2014
- Messages
- 82
Friends,
I am having trouble creating a key in the registry from VBA. I have the proper declaration for RegCreateKeyEx. I am able to use the following code to attempt to create HKEY_CLASSES_ROOT\Admin (which already exists). The return value is 0 with a status of 2 meaning "already exists". That's fine but I want to insert/create a GUID key underneath /AppID and I get a return value of 5 which is permissions related. Here is the test code that I am using. Does anyone know what I am doing wrong? I seem to have the right permissions for /AppID but this code fails anyway.
Additional info:
I have a .reg file with this key in it that I can run that works under my userID. That tells me that I have the right permissions.
I am having trouble creating a key in the registry from VBA. I have the proper declaration for RegCreateKeyEx. I am able to use the following code to attempt to create HKEY_CLASSES_ROOT\Admin (which already exists). The return value is 0 with a status of 2 meaning "already exists". That's fine but I want to insert/create a GUID key underneath /AppID and I get a return value of 5 which is permissions related. Here is the test code that I am using. Does anyone know what I am doing wrong? I seem to have the right permissions for /AppID but this code fails anyway.
Code:
Sub TestRegCreateKey()
Dim secAttr As SECURITY_ATTRIBUTES
Dim subkey As String
Dim retval As Long
Dim section As Long
section = HKEY_CLASSES_ROOT
'subkey = "AppID"
subkey = "AppID\\{5B076C03-2F26-11CF-9AE5-0800096E19F4}"
'subkey = "AppID\\Crew"
secAttr.nLength = Len(secAttr) ' size of the structure
secAttr.lpSecurityDescriptor = 0 ' default security level
secAttr.bInheritHandle = True ' the default value for this setting
retval = RegCreateKey(section, subkey, secAttr)
End Sub
Public Function RegCreateKey(section As Long, subkey As String, secAttr As SECURITY_ATTRIBUTES) As Long
'12/29/14 2064 -car- Created function to add new keys to registry
Dim hregkey As Long ' receives handle to the newly created or opened registry key
Dim neworused As Long ' receives 1 if new key was created or 2 if an existing key was opened
Dim retval As Long ' return value
' Create or open the registry key
retval = OSRegCreateKeyEx(section, subkey, 0, "", 0, KEY_WRITE, secAttr, hregkey, neworused)
If retval <> 0 Then ' error during open
Debug.Print "Error " & retval & " -- aborting."
End ' terminate the program
Else
Debug.Print "Registry key " & section & "\" & subkey & " created or pre-existing."
End If
End Function
Additional info:
I have a .reg file with this key in it that I can run that works under my userID. That tells me that I have the right permissions.
Last edited: