Results 1 to 12 of 12

Thread: RegOpenKeyEx + RegDeleteKey on Vista

  1. #1

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

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

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  2. #2

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: RegOpenKeyEx + RegDeleteKey on Vista

    *bump*
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  3. #3

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: RegOpenKeyEx + RegDeleteKey on Vista

    *Quite an old thread, but still haven't figured this one out...*

    Any Ideas?

    *BUMP*
    Last edited by some1uk03; Aug 5th, 2009 at 11:01 AM.
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  4. #4

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: RegOpenKeyEx + RegDeleteKey on Vista

    *BUMP*

    This is almost a few months old. Someone must have any clues?
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  5. #5
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    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.

  6. #6
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: RegOpenKeyEx + RegDeleteKey on Vista

    i googled this: "HKCR vista" and got a lot of results
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  7. #7
    Lively Member Garrcomm's Avatar
    Join Date
    Jul 2009
    Location
    the Netherlands
    Posts
    87

    Re: RegOpenKeyEx + RegDeleteKey on Vista

    From what I've read @ http://www.vistax64.com/vista-accoun...rmissions.html :
    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.
    If a thread is solved, please click on Thread Tools / Mark Thread Resolved .
    If someone helped you very good, consider rating his post by clicking the icon under his name.

  8. #8

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    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 View Post
    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
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  9. #9
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: RegOpenKeyEx + RegDeleteKey on Vista

    Quote Originally Posted by some1uk03 View Post
    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.

  10. #10

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    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!
    Last edited by some1uk03; Aug 6th, 2009 at 02:16 PM.
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  11. #11

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    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?
    Attached Images Attached Images  
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  12. #12

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: RegOpenKeyEx + RegDeleteKey on Vista

    *bumpy bump*
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width