windows RegOpenKeyEx 在失败时返回什么错误代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2284904/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:57:13  来源:igfitidea点击:

What error codes does RegOpenKeyEx return on failure?

windowswinapiregistry

提问by gdunbar

The MSDN documentation:

MSDN 文档:

http://msdn.microsoft.com/en-us/library/ms724897(VS.85).aspx

http://msdn.microsoft.com/en-us/library/ms724897(VS.85).aspx

Is strangely silent on what errors this function might return.

奇怪的是,这个函数可能会返回什么错误。

I'm particularly interested in what error code is returned if the key doesn't exist, but more comprehensive information would be nice too.

如果密钥不存在,我对返回什么错误代码特别感兴趣,但更全面的信息也会很好。

采纳答案by John Knoeller

This is a standard Win32 kernel error code. The kind of code that GetLastError() returns, so the set of possible values can be found in WinError.h. Note that these are notHRESULT values.

这是标准的 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

A comprehensive list of possible error codes from RegOpenKeyEx would be quite large and likely to change with each version of Windows, You should be prepared to handle any Win32 error code.

来自 RegOpenKeyEx 的可能错误代码的完整列表将非常大,并且可能会随着每个版本的 Windows 发生变化,您应该准备好处理任何 Win32 错误代码。

Edit: Apparently the error for a non-existent key is ERROR_FILE_NOT_FOUND.

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

回答by Patrick

Why don't you simply try it and see in the debugger what it returns?

为什么不简单地尝试一下并在调试器中查看它返回的内容?

In the Visual Studio debugger you can simply enter

在 Visual Studio 调试器中,您只需输入

$err

to see the error code of the last executed function, and

查看最后执行的函数的错误代码,以及

$err,hr

to see the last error in full text.

以全文查看最后一个错误。

回答by Ivan

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

has already been noted by gdunbar.

gdunbar 已经注意到了。

I just encountered

我刚遇到

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

while erroneously using a path name starting with a '\\'character.

同时错误地使用以'\\'字符开头的路径名。