Results 1 to 5 of 5

Thread: RegOpenKey not working

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    RegOpenKey not working

    I always get this error:

    RegOpenKeyEx failed with error code : 2

    Please can some one explain why this is happening i am using an admin account


    Code:
    fResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
                    KeyName, 0, _
                    READ_CONTROL Or WRITE_DAC, hkey)
        If fResult <> ERROR_SUCCESS Then
            MsgBox "RegOpenKeyEx failed with error code : " & fResult
        Else
            UpdatePermissionsOfRegistryKey hkey, Accounts
            RegCloseKey hkey
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  2. #2
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    Re: RegOpenKey not working

    RegOpenKeyEx HKEY_CURRENT_USER, "YourSubkey", 0, KEY_ALL_ACCESS, Result

    The Result and Hkey are reversed in your code.
    It returns the Hkey and delivers a Result in an argument.
    why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
    for every question you ask provide an answer on another thread.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: RegOpenKey not working

    thanks,

    Does anybody know how to fix it, it sets permissions on the reg keys
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: RegOpenKey not working

    Did you reverse Result and Hkey in your code?

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

    Re: RegOpenKey not working

    @ chris1990. Your code is correct for what you are trying to achieve. The error code 2 is telling you (most likely) that the subkey doesn't exist. Do a Debug.Print on "KeyName" and check that it already exists in the registry to make sure it's valid.

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