RegOpenKeyEx + RegDeleteKey on Vista
I'm having an issue with Vista and being able to delete a key from HKCR.
I've been having some trouble for quite some time on this but no matter what I try, it just wont delete the Key.
It works on HKCU & HKLM, but not with HKCR (Hkey_Classes_Root)... I'm logged in as an Admin, Running Vista.
The App has an asInvoker Manifest (tried with requireAdministrator) but same thing..
I've tried KEY_READ, KEY_QUERY_VALUE, KEY_ALL_ACCESS, but it either returns 0 or 5 (Access Denied)
Note: This is the UniCode aware version RegOpenKeyExW
Code:
Private Const KEY_QUERY_VALUE As Long = &H1
Private Const KEY_SET_VALUE As Long = &H2
Private Const KEY_CREATE_SUB_KEY As Long = &H4
Private Const KEY_ENUMERATE_SUB_KEYS As Long = &H8
Private Const KEY_NOTIFY As Long = &H10
Private Const KEY_CREATE_LINK As Long = &H20
Private Const KEY_ALL_ACCESS As Long = &H3F
Private Const KEY_WOW64_64KEY = &H100
Private Const KEY_WOW64_32KEY = &H200
Private Const READ_CONTROL As Long = &H20000
Private Const STANDARD_RIGHTS_REQUIRED As Long = &HF0000
Private Const STANDARD_RIGHTS_READ As Long = READ_CONTROL
Private Const STANDARD_RIGHTS_WRITE As Long = READ_CONTROL
Private Const STANDARD_RIGHTS_EXECUTE As Long = READ_CONTROL
Private Const KEY_READ As Long = STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY
Private Const KEY_WRITE As Long = STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExW" _
(ByVal hKey As Long, ByVal lpSubKey As Long, ByVal ulOptions As Long, ByVal samDesired As Long, _
phkResult As Long) As Long
If regDoes_Key_Exist(lngRootKey, strRegKeyPath) Then
m_lngRetVal = RegOpenKeyEx(lngRootKey, StrPtr(strRegKeyPath), 0, KEY_READ, lngKeyHandle)
'MSGBox the result for testing purposes
MsgBox strRegKeyPath, vbOKOnly, m_lngRetVal
If m_lngRetVal = ERROR_SUCCESS Then
m_lngRetVal = RegDeleteKey(lngKeyHandle, StrPtr(strRegKeyName))
If m_lngRetVal = 0 Then regDelete_A_Key = True
m_lngRetVal = RegCloseKey(lngKeyHandle)
End If
End If
Re: RegOpenKeyEx + RegDeleteKey on Vista
Re: RegOpenKeyEx + RegDeleteKey on Vista
*Quite an old thread, but still haven't figured this one out...*
Any Ideas?
*BUMP*
Re: RegOpenKeyEx + RegDeleteKey on Vista
*BUMP*
This is almost a few months old. Someone must have any clues?
Re: RegOpenKeyEx + RegDeleteKey on Vista
Do you have the relevant permissions to access this subkey? Sometimes Admin privileges aren't good enough. In regedit, right-click on the subkey and click "Permissions".
In any case you should use KEY_SET_VALUE.
Re: RegOpenKeyEx + RegDeleteKey on Vista
i googled this: "HKCR vista" and got a lot of results
Re: RegOpenKeyEx + RegDeleteKey on Vista
From what I've read @ http://www.vistax64.com/vista-accoun...rmissions.html :
Quote:
Note that HKEY_CLASSES_ROOT is HKEY_LOCAL_MACHINE\Software\Classes and
HKEY_CURRENT_USER\Software\Classes combined together, with entries in
HKCU taking precedence.
If it's combined, I can only guess that it's read-only and you should try to one of those other two paths.
Re: RegOpenKeyEx + RegDeleteKey on Vista
Thanks for the suggestions guys...
The whole process here is that I'm doing a registry utility which scans & fixes corrupt paths etc...
Quote:
Originally Posted by
schoolbusdriver
Do you have the relevant permissions to access this subkey? Sometimes Admin privileges aren't good enough. In regedit, right-click on the subkey and click "Permissions".
In any case you should use KEY_SET_VALUE.
Manually right-clicking in regedit is not an option really, because I can't expect the end user to manually go and do this.
Garrcomm
How would you check if they're combined or not?
I'm thinking, shall I scan
HKEY_CURRENT_USER\Software\Classes instead or
HKEY_LOCAL_MACHINE\Software\Classes instead or
HKCR
Re: RegOpenKeyEx + RegDeleteKey on Vista
Quote:
Originally Posted by
some1uk03
Manually right-clicking in regedit is not an option really, because I can't expect the end user to manually go and do this.
Obviously. However, if YOU can determine it's a permissions issue, you may be able to write code to compensate.
Re: RegOpenKeyEx + RegDeleteKey on Vista
That link seems quite interesting actually. It says:
"If you write keys to a key under HKEY_CLASSES_ROOT, the system stores
the information under HKEY_LOCAL_MACHINE\Software\Classes. If you write
values to a key under HKEY_CLASSES_ROOT, and the key already exists
under HKEY_CURRENT_USER\Software\Classes, the system will store the
information there instead of under HKEY_LOCAL_MACHINE\Software\Classes."
So, in theory, I should be scanning in HKEY_CURRENT_USER\Software\Classes in Vista & Windows 7, but HKCU in XP
------------------EDIT-------------------
Actually no, my theory is corrupt. It is still HKCR that needs to be scanned!
Is there a way to check the security permissions of a key in VB? If that's possible, then I think problem sorted!
1 Attachment(s)
Re: RegOpenKeyEx + RegDeleteKey on Vista
Ok I've found out a way to check for a RegistryKey Owner Info from here
But it only tells me the owner of a key, if its Admin or User.
I've also managed to narrow down the issue. The image below shows:
Whilst scanning, it should check If the permission of a KEY is CREATOR OWNER, then I can use it.
However, if the permission is SYSTEM then ignore it.
Can this API; RegGetKeySecurity return that info?
Re: RegOpenKeyEx + RegDeleteKey on Vista