载入中
自定义HTML载入中... loading
RegSaveKey 函数 [翻译 2008-03-24 17:38:30]   
字体变小 字体变大
The RegSaveKey function saves the specified key and all of its subkeys and values to a new file in the standard format.

To specify the format for the saved key or hive, use the RegSaveKeyEx function.
定义
LONG RegSaveKey(HKEY hKey, LPCTSTR lpFile, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
参数
  hKey
    [in] Handle to an open key. 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
  lpFile
    [in] Pointer to a null-terminated string containing the name of the file in which the specified key and subkeys are saved. If the file already exists, the function fails.

If the string does not include a path, the file is created in the current directory of the calling process for a local key, or in the %systemroot%\system32 directory for a remote key. The new file has the archive attribute.

Windows Me/98/95: The new file has the archive, hidden, read-only, and system attributes. RegSaveKey does not support long file names. To save a registry hive to a file with a long file name, first save the hive to a short file name, then rename the resulting file to its long file name. If the string does not include a path, the file is created in the Windows root directory for local and remote keys. For more information, see GetWindowsDirectory.
  lpSecurityAttributes
    [in] Pointer to a SECURITY_ATTRIBUTES structure that specifies a security descriptor for the new file. If lpSecurityAttributes is NULL, the file gets a default security descriptor. The ACLs in a default security descriptor for a file are inherited from its parent directory.
返回值
  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.

If the file already exists, the function fails with the ERROR_ALREADY_EXISTS error.

Windows Me/98/95: If the file already exists, the function fails with the ERROR_REGISTRY_IO_FAILED error.
说明
  If hKey represents a key on a remote computer, the path described by lpFile is relative to the remote computer.

The RegSaveKey function saves only nonvolatile keys. It does not save volatile keys. A key is made volatile or nonvolatile at its creation; see RegCreateKeyEx.

You can use the file created by RegSaveKey in subsequent calls to the RegLoadKey, RegReplaceKey, or RegRestoreKey functions. If RegSaveKey fails part way through its operation, the file will be corrupt and subsequent calls to RegLoadKey, RegReplaceKey, or RegRestoreKey for the file will fail.

RegSaveKey is often used in conjunction with RegRestoreKey to copy subtrees in the registry. An alternative to this approach is to use the SHCopyKey function.

The calling process must have the SE_BACKUP_NAME privilege enabled. For more information, see Running with Special Privileges.
系统要求
  Client: Requires Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.
Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Header: Declared in Winreg.h; include Windows.h.
Library: Link to Advapi32.lib.
DLL: Requires Advapi32.dll.
Unicode: Implemented as RegSaveKeyW (Unicode) and RegSaveKeyA (ANSI). Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode.
1/   RegSaveKey()函数是将指定的关键字和它的子关键字及相关值写入指定  
        文件中,一般是用来保存注册表中的一段信息。入口参数有三个,第一  
        个是   hKey,它是你想保存的关键字的句柄,可以是系统预定义的,  
        也可以是用RegOpenKey()打开或是RegCreateKeyEx()创建的。第二个  
        参数是lpFile,它就是用于保存信息的文件名称,注意,这个文件必须是  
        不存在的,而且如果你是将它保存到一个FAT文件系统中,那么也不能有  
        扩展名(否则RegRestoreKey()函就读不出来)。最后一个参数是  
        lpSecurityAttributes,它在NT系统中用来设置新文件的安全属性,而  
        在Win95中这个参数是被忽略的,可以直接写NULL。  
   
  2/   RegRestoreKey()函数是将用RegSaveKey()函数保存的注册表信息文件  
        的内容重新读入到注册表的指定关键字下。如果只是做恢复性工作,
        那么它的头两个参数可以和调用RegSaveKey()函数的头两个参数一样,  
        如果hKey参数改变了,则文件中的信息就会写到新指定的关键字下。最  
        后一个参数dwFlage是指定这个关键字是否是易挥发的。  
   
  3/   RegSaveKey()函数可以工作在NT和Win95平台下,而RegRestoreKey()  
        函数则只能工作在NT平台下。所以如果你工作在Win95平台下,你就不能  
        使用RegRestoreKey()函数.  
分类: 编程基础
所属版块: 科技
票数:
什么是“我顶”?
点击数:    评论数:
本文章引用通告地址(TrackBack Ping URL)为:
本文章尚未被引用。
发表评论
大 名:
(不填写则显示为匿名者)
网 址:
(您的网址,可以不填)
标 题:
内 容:
请根据下图中的字符输入验证码:
(您的评论将有可能审核后才能发表)
和讯个人门户 v1.0 | 和讯部落 | 客服中心