RegOpenKeyEx在失败时返回哪些错误代码?

4
3个回答

3

这是一个标准的Win32内核错误代码。它是由 GetLastError() 返回的,所以可能的值集合可以在 WinError.h 中找到。请注意,这些不是 HRESULT 值。

//  The configuration registry database is corrupt.
//
#define ERROR_BADDB                      1009L

//  The configuration registry key is invalid.
//
#define ERROR_BADKEY                     1010L

//  The configuration registry key could not be opened.
//
#define ERROR_CANTOPEN                   1011L

//  The configuration registry key could not be read.
//
#define ERROR_CANTREAD                   1012L

//  The configuration registry key could not be written.
//
#define ERROR_CANTWRITE                  1013L

//  One of the files in the registry database had to be recovered by use of a log or alternate copy. The recovery was successful.
//
#define ERROR_REGISTRY_RECOVERED         1014L

//  The registry is corrupted. The structure of one of the files containing registry data is corrupted, or the system's memory image of the file is corrupted, or the file could not be recovered because the alternate copy or log was absent or corrupted.
//
#define ERROR_REGISTRY_CORRUPT           1015L

//  An I/O operation initiated by the registry failed unrecoverably. The registry could not read in, or write out, or flush, one of the files that contain the system's image of the registry.
//
#define ERROR_REGISTRY_IO_FAILED         1016L

//  The system has attempted to load or restore a file into the registry, but the specified file is not in a registry file format.
//
#define ERROR_NOT_REGISTRY_FILE          1017L

//  Illegal operation attempted on a registry key that has been marked for deletion.
//
#define ERROR_KEY_DELETED                1018L

//  System could not allocate the required space in a registry log.
//
#define ERROR_NO_LOG_SPACE               1019L

//  Cannot create a symbolic link in a registry key that already has subkeys or values.
//
#define ERROR_KEY_HAS_CHILDREN           1020L

//  Cannot create a stable subkey under a volatile parent key.
//
#define ERROR_CHILD_MUST_BE_VOLATILE     1021L

RegOpenKeyEx可能出现的错误代码种类繁多,而且很可能会因为Windows版本的更新而发生变化。因此,您应当准备好处理任何Win32错误代码。

编辑: 显然,不存在键的错误代码是ERROR_FILE_NOT_FOUND。


虽然这些信息很有帮助,但注册表错误列表只是一个参考,实际返回的内容可能会有所不同。如果打开一个不存在的键(我使用的是HKCU"SoftwareX"),则会返回2或ERROR_FILE_NOT_FOUND。 - gdunbar

1
为什么不在调试器中尝试并查看它返回了什么?
在Visual Studio调试器中,您可以简单地输入
$err

要查看上次执行函数的错误代码,以及

$err,hr

查看完整的最后一个错误文本。


当然我可以做到(而且我刚刚做到了...返回ERROR_FILE_NOT_FOUND)。然而,我希望未来有任何寻找相同内容的人能够在这里找到比MSDN非列表更好的参考资料。 - gdunbar

0
ERROR_FILE_NOT_FOUND
    2 (0x2)
    The system cannot find the file specified.

已经被gdunbar注意到了。

我刚刚遇到了

ERROR_BAD_PATHNAME
    161 (0xA1)
    The specified path is invalid.

在编程中错误地使用以'\\'字符开头的路径名。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接