Menu

RegCreateKeyExA();

2004-07-25
2012-09-26
  • Nobody/Anonymous

    Hello to all.
    I am trying to write a key in the registry, but my knowledge of lenguage C are basic; I looked for documentation WIN32 API HELP, but I do not know like putting argument 8, and in the argument 9 the compiler say badly that this.
    Somebody can complete my code, and say to me if there is some error in the same one?.
    Excuse the extension for the message.

    Thank you...
    Gerardo.

    [CODE]

    #include <windows.h>

    LONG RegCreateKeyEx(

        HKEY  hKey,    // handle of an open key
        LPCTSTR  lpszSubKey,    // address of subkey name
        DWORD  dwReserved,    // reserved
        LPTSTR  lpszClass,    // address of class string
        DWORD  fdwOptions,    // special options flag
        REGSAM  samDesired,    // desired security access
        LPSECURITY_ATTRIBUTES  lpSecurityAttributes,    // address of key security structure
        PHKEY  phkResult,    // address of buffer for opened handle 
        LPDWORD  lpdwDisposition     // address of disposition value buffer
       );

    int main()
    {
        //Prototype
        //RegCreateKeyExA(HKEY__ *, const char *, long unsigned int, char *, long unsigned int, long unsigned int, _SECURITY_ATTRIBUTES *, HKEY__ **, DWORD *)
      
       RegCreateKeyExA(HKEY_CLASSES_ROOT ,"Secret Shhhh" ,0 ,"" ,REG_OPTION_NON_VOLATILE ,KEY_READ ,NULL , I don't Know   ,REG_CREATED_NEW_KEY );

       return 0;

    }

    [\CODE]

    The documentation says:

    The RegCreateKeyEx function creates the specified key. If the key already exists in the registry, the function opens it.

    LONG RegCreateKeyEx(

        HKEY  hKey,    // handle of an open key
        LPCTSTR  lpszSubKey,    // address of subkey name
        DWORD  dwReserved,    // reserved
        LPTSTR  lpszClass,    // address of class string
        DWORD  fdwOptions,    // special options flag
        REGSAM  samDesired,    // desired security access
        LPSECURITY_ATTRIBUTES  lpSecurityAttributes,    // address of key security structure
        PHKEY  phkResult,    // address of buffer for opened handle 
        LPDWORD  lpdwDisposition     // address of disposition value buffer
       );   
    Parameters

    hKey

    Identifies a currently open key or any of the following predefined reserved handle values:

    HKEY_CLASSES_ROOT
    HKEY_CURRENT_USER
    HKEY_LOCAL_MACHINE
    HKEY_USERS

    The key opened or created by the RegCreateKeyEx function is a subkey of the key identified by the hKey parameter.

    lpszSubKey

    Points to a null-terminated string specifying the name of a subkey that this function opens or creates. The subkey specified must be a subkey of the key identified by the hKey parameter. This subkey must not begin with the backslash character ('\'). This parameter cannot be NULL.

    dwReserved

    Reserved; must be zero.

    lpszClass

    Points to a null-terminated string that specifies the class (object type) of this key. This parameter is ignored if the key already exists.

    fdwOptions

    Specifies special options for the key. Currently, this parameter can be one of the following values:

    Value    Meaning
    REG_OPTION_VOLATILE    Windows 95: This value is ignored in Windows 95. That is, even if REG_OPTION_VOLATILE is specified, the RegCreateKeyEx function creates a nonvolatile key and returns ERROR_SUCCESS.Windows NT: This key is volatile; the information is stored in memory and is not preserved when the system is restarted. The RegSaveKey function does not save volatile keys.

    REG_OPTION_NON_VOLATILE    This key is not volatile; the information is stored in a file and is preserved when the system is restarted. The RegSaveKey function saves keys that are not volatile.
    By default, keys are not volatile. This option is ignored if the key already exists.
    The RegSaveKey function only saves nonvolatile keys. It does not save volatile keys.

    samDesired

    Specifies an access mask that specifies the desired security access for the new key. This parameter can be a combination of the following values:

    Value    Meaning
    KEY_ALL_ACCESS    Combination of KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, KEY_NOTIFY, KEY_CREATE_SUB_KEY, KEY_CREATE_LINK, and KEY_SET_VALUE access.
    KEY_CREATE_LINK    Permission to create a symbolic link.
    KEY_CREATE_SUB_KEY    Permission to create subkeys.
    KEY_ENUMERATE_SUB_KEYS    Permission to enumerate subkeys.
    KEY_EXECUTE    Permission for read access.
    KEY_NOTIFY    Permission for change notification.
    KEY_QUERY_VALUE    Permission to query subkey data.
    KEY_READ    Combination of KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, and KEY_NOTIFY access.
    KEY_SET_VALUE    Permission to set subkey data.
    KEY_WRITE    Combination of KEY_SET_VALUE and KEY_CREATE_SUB_KEY access.
    lpSecurityAttributes

    Points to a SECURITY_ATTRIBUTES structure that specifies the security attributes for the new key.
    If this parameter is NULL, the key receives a default security descriptor. If the operating system does not support security, this parameter is ignored.

    phkResult

    Points to a variable that receives the handle of the opened or created key.

    lpdwDisposition

    Points to a variable that receives one of the following disposition values:

    Value    Meaning
    REG_CREATED_NEW_KEY    The key did not exist and was created.
    REG_OPENED_EXISTING_KEY    The key existed and was simply opened without being changed.
    Return Value

    If the function succeeds, the return value is ERROR_SUCCESS.
    If the function fails, the return value is an error value.

    Remarks

    The key that the RegCreateKeyEx function creates has no values. An application can use the RegSetValue or RegSetValueEx function to set key values.
    The key identified by the hKey parameter must have been opened with KEY_CREATE_SUB_KEY access. To open the key, use the RegCreateKeyEx or RegOpenKeyEx function.
    An application cannot create a key under HKEY_USERS or HKEY_MACHINE.
    An application can use RegCreateKeyEx to temporarily lock a portion of the registry. When the locking process creates a new key, it receives the disposition value REG_CREATED_NEW_KEY, indicating that it "owns" the lock. Another process attempting to create the same key receives the disposition value REG_OPENED_EXISTING_KEY, indicating that another process already owns the lock.

     
    • Nobody/Anonymous

      Just create...

      HKEY hResult = NULL;

      RegCreateKeyEx(..., &hResult, REG_CREATED_NEW_KEY);

      =)

      Kip

       
    • Nobody/Anonymous

      Almost I already have it Kip, ;) , single that argument 9 gives error.

      passing `int' to argument 9 of `RegCreateKeyExA(HKEY__ *, const char *, long unsigned int, char *, long unsigned int, long unsigned int, _SECURITY_ATTRIBUTES *, HKEY__ **, DWORD *)' lacks a cast

      Greetings.

      Ger.

       
    • Nobody/Anonymous

      Show me your statement =)

      Kip

       
    • Anonymous

      Anonymous - 2004-07-25

      Arg 9 is a DWORD pointer (LPDWORD) not an integer.

      Declare:

      DWORD disposition = REG_CREATED_NEW_KEY ;

      Then pass &disposition as argument 9. Liker this:

      HKEY hResult = NULL;
      DWORD disposition = REG_CREATED_NEW_KEY ;

      RegCreateKeyEx(..., &hResult, &disposition ) ;

      Clifford

       
    • Nobody/Anonymous

      Ok; thank you very much to both.
      I had solved it clumsily:

      HKEY hResult = NULL;
      DWORD dDisposition;

      RegCreateKeyEx(...,&hResult, &dDisposition);

      but obvious he was bad. Also I could create a key, but after eliminating it and modifying the parameters I could not create another new one; I will continue investigating...  :)
      Now I have to do how to put something in the key, like for example the date in which she was created.

      Greetings.

      Ger.

       
      • Nobody/Anonymous

        Ok; it had to close and to return to open the Regedit....

        ..."but after eliminating it and modifying the parameters I could not create another new one"...

        Buuuuuh!

        Ger.

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.