Từ 1 tới 2 trên tổng số 2 kết quả

Đề tài: cách sử dụng hàm RegCreateKeyEx

  1. #1
    Ngày gia nhập
    02 2008
    Bài viết
    1,009

    Mặc định cách sử dụng hàm RegCreateKeyEx

    RegCreateKeyEx Function

    Creates the specified registry key. If the key already exists, the function opens it. Note that key names are not case sensitive.

    To perform transacted registry operations on a key, call the RegCreateKeyTransacted function.


    Syntax
    Visual C++ Code:
    1. LONG WINAPI RegCreateKeyEx(
    2.   __in        HKEY hKey,
    3.   __in        LPCTSTR lpSubKey,
    4.   __reserved  DWORD Reserved,
    5.   __in_opt    LPTSTR lpClass,
    6.   __in        DWORD dwOptions,
    7.   __in        REGSAM samDesired,
    8.   __in_opt    LPSECURITY_ATTRIBUTES lpSecurityAttributes,
    9.   __out       PHKEY phkResult,
    10.   __out_opt   LPDWORD lpdwDisposition
    11. );

    Parameters
    hKey
    A handle to an open registry key. The calling process must have KEY_CREATE_SUB_KEY access to the key. For more information, see Registry Key Security and Access Rights.

    This handle is returned by the RegCreateKeyEx or RegOpenKeyEx function, or it can be one of the following predefined keys:


    HKEY_CLASSES_ROOT
    HKEY_CURRENT_CONFIG
    HKEY_CURRENT_USER
    HKEY_LOCAL_MACHINE
    HKEY_USERS

    lpSubKey
    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; it can be up to 32 levels deep in the registry tree. For more information on key names, see Structure of the Registry.

    This parameter cannot be NULL.

    Reserved
    This parameter is reserved and must be zero.

    lpClass
    The class (object type) of this key. This parameter may be ignored. This parameter can be NULL.

    This parameter is used for both local and remote registry keys.

    dwOptions
    This parameter can be one of the following values.

    Value Meaning
    REG_OPTION_BACKUP_RESTORE
    0x00000004L
    If this flag is set, the function ignores the samDesired parameter and attempts to open the key with the access required to backup or restore the key. If the calling thread has the SE_BACKUP_NAME privilege enabled, the key is opened with the ACCESS_SYSTEM_SECURITY and KEY_READ access rights. If the calling thread has the SE_RESTORE_NAME privilege enabled, the key is opened with the ACCESS_SYSTEM_SECURITY and KEY_WRITE access rights. If both privileges are enabled, the key has the combined access rights for both privileges. For more information, see Running with Special Privileges.

    REG_OPTION_CREATE_LINK
    0x00000002L
    This key is a symbolic link. The target path is assigned to the L"SymbolicLinkValue" value of the key. The target path must be an absolute registry path.

    Registry symbolic links should be used only when absolutely necessary for application compatibility.

    REG_OPTION_NON_VOLATILE
    0x00000000L
    This key is not volatile; this is the default. The information is stored in a file and is preserved when the system is restarted. The RegSaveKey function saves keys that are not volatile.

    REG_OPTION_VOLATILE
    0x00000001L
    All keys created by the function are volatile. The information is stored in memory and is not preserved when the corresponding registry hive is unloaded. For HKEY_LOCAL_MACHINE, this occurs when the system is shut down. For registry keys loaded by the RegLoadKey function, this occurs when the corresponding RegUnLoadKey is performed. The RegSaveKey function does not save volatile keys. This flag is ignored for keys that already exist.


    samDesired
    A mask that specifies the access rights for the key. For more information, see Registry Key Security and Access Rights.

    lpSecurityAttributes
    A pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpSecurityAttributes is NULL, the handle cannot be inherited.

    The lpSecurityDescriptor member of the structure specifies a security descriptor for the new key. If lpSecurityAttributes is NULL, the key gets a default security descriptor. The ACLs in a default security descriptor for a key are inherited from its direct parent key.

    phkResult
    A pointer to a variable that receives a handle to the opened or created key. If the key is not one of the predefined registry keys, call the RegCloseKey function after you have finished using the handle.

    lpdwDisposition
    A pointer to a variable that receives one of the following disposition values.

    Value Meaning
    REG_CREATED_NEW_KEY
    0x00000001L
    The key did not exist and was created.

    REG_OPENED_EXISTING_KEY
    0x00000002L
    The key existed and was simply opened without being changed.


    If lpdwDisposition is NULL, no disposition information is returned.

    Return Value
    If the function succeeds, the return value is ERROR_SUCCESS.

    If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.

    Remarks
    The key that the RegCreateKeyEx function creates has no values. An application can use the RegSetValueEx function to set key values.

    An application cannot create a key that is a direct child of HKEY_USERS or HKEY_LOCAL_MACHINE. An application can create subkeys in lower levels of the HKEY_USERS or HKEY_LOCAL_MACHINE trees.

    If your service or application impersonates different users, do not use this function with HKEY_CURRENT_USER. Instead, call the RegOpenCurrentUser function.

    Note that operations that access certain registry keys are redirected. For more information, see Registry Virtualization and 32-bit and 64-bit Application Data in the Registry.
    đây là hướng dẫn của MSDN nhưng mình không làm được,anh em thử xem hộ mình,mình định ghi vào regedit như sau
    Bằng cách thay đổi registry
    Hive: HKEY_CURRENT_USER
    Key: Software\Microsoft\Windows\CurrentVersion\Policies \System
    Name: DisableTaskMgr
    Type: REG_DWORD
    Value: 1=Enablethis key, that is DISABLE TaskManager
    Value: 0=Disablethis key, that is Don't Disable, Enable TaskManager.
    đây là code mình tự làm
    Visual C++ Code:
    1. #include<iostream.h>
    2. #include<stdio.h>
    3. #include<windows.h>
    4. void tao()
    5. {
    6.     HKEY  ketqua ;
    7.     HKEY  ketqua1;
    8.     DWORD contro=REG_OPENED_EXISTING_KEY;
    9.     RegCreateKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies \\System",
    10.     &ketqua);
    11.     RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies \\System",
    12.     0,"DisableTaskMgr",REG_OPTION_VOLATILE,KEY_SET_VALUE,NULL,&ketqua1,&contro);
    13.  
    14. }
    15. int main()
    16. {
    17.     tao();
    18. }

  2. #2
    Ngày gia nhập
    07 2008
    Nơi ở
    /media/Anime
    Bài viết
    2,288

    bạn sửa lại như vầy thì sẽ chạy :
    Visual C++ Code:
    1. void tao()
    2. {
    3.     HKEY ketqua ;
    4.     DWORD data = 1;
    5.    
    6.     RegCreateKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",&ketqua);
    7.     RegSetValueEx(ketqua,"DisableTaskMgr",0,REG_DWORD,(unsigned char *)&data,sizeof(data));
    8. }
    Càng yêu mèo thì mèo càng mập. Mèo càng mập ta lại càng yêu.

Các đề tài tương tự

  1. Sử dụng hàm api RegCreateKeyEx
    Gửi bởi congdongc trong diễn đàn Thắc mắc lập trình Visual C++
    Trả lời: 2
    Bài viết cuối: 23-01-2009, 03:36 PM

Quyền hạn của bạn

  • Bạn không thể gửi đề tài mới
  • Bạn không thể gửi bài trả lời
  • Bạn không thể gửi các đính kèm
  • Bạn không thể chỉnh sửa bài viết của bạn