Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Windows7中读取注册表行为异常 我试图读取C++中Windows 7中注册表的“(默认)”值,下面是我使用的代码: string GetSZValueUnique( HKEY openKey, const char* regkey, const char* keyName ) { HKEY hKey = 0; BYTE data[512] ; DWORD szsize = 512 ; string value ; LONG retValue = RegOpenKeyEx( openKey, regkey, 0, KEY_READ, &hKey ) ; if ( retValue == ERROR_SUCCESS ) { LONG retV = RegQueryValueEx( hKey, keyName, 0, 0, data, &szsize ) ; if ( retV == ERROR_SUCCESS ) { char* _value = reinterpret_cast<char*>(data) ; value = _value ; RegCloseKey (hKey) ; return value ; } else { char msg[512] ; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,(DWORD)retV,0,&msg[0],512,0) ; error_string = &msg[0]; MessageBox( 0, error_string.c_str(), "Query : GetSZValueUnique", 0 ); } } else { char msg[512] ; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,(DWORD)retV,0,&msg[0],512,0) ; error_string = &msg[0]; MessageBox( 0, error_string.c_str(), "Open : GetSZValueUnique", 0 ); } RegCloseKey (hKey) ; return "" ; }_C++_Winapi_Windows 7 - Fatal编程技术网

在Windows7中读取注册表行为异常 我试图读取C++中Windows 7中注册表的“(默认)”值,下面是我使用的代码: string GetSZValueUnique( HKEY openKey, const char* regkey, const char* keyName ) { HKEY hKey = 0; BYTE data[512] ; DWORD szsize = 512 ; string value ; LONG retValue = RegOpenKeyEx( openKey, regkey, 0, KEY_READ, &hKey ) ; if ( retValue == ERROR_SUCCESS ) { LONG retV = RegQueryValueEx( hKey, keyName, 0, 0, data, &szsize ) ; if ( retV == ERROR_SUCCESS ) { char* _value = reinterpret_cast<char*>(data) ; value = _value ; RegCloseKey (hKey) ; return value ; } else { char msg[512] ; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,(DWORD)retV,0,&msg[0],512,0) ; error_string = &msg[0]; MessageBox( 0, error_string.c_str(), "Query : GetSZValueUnique", 0 ); } } else { char msg[512] ; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,(DWORD)retV,0,&msg[0],512,0) ; error_string = &msg[0]; MessageBox( 0, error_string.c_str(), "Open : GetSZValueUnique", 0 ); } RegCloseKey (hKey) ; return "" ; }

在Windows7中读取注册表行为异常 我试图读取C++中Windows 7中注册表的“(默认)”值,下面是我使用的代码: string GetSZValueUnique( HKEY openKey, const char* regkey, const char* keyName ) { HKEY hKey = 0; BYTE data[512] ; DWORD szsize = 512 ; string value ; LONG retValue = RegOpenKeyEx( openKey, regkey, 0, KEY_READ, &hKey ) ; if ( retValue == ERROR_SUCCESS ) { LONG retV = RegQueryValueEx( hKey, keyName, 0, 0, data, &szsize ) ; if ( retV == ERROR_SUCCESS ) { char* _value = reinterpret_cast<char*>(data) ; value = _value ; RegCloseKey (hKey) ; return value ; } else { char msg[512] ; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,(DWORD)retV,0,&msg[0],512,0) ; error_string = &msg[0]; MessageBox( 0, error_string.c_str(), "Query : GetSZValueUnique", 0 ); } } else { char msg[512] ; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,(DWORD)retV,0,&msg[0],512,0) ; error_string = &msg[0]; MessageBox( 0, error_string.c_str(), "Open : GetSZValueUnique", 0 ); } RegCloseKey (hKey) ; return "" ; },c++,winapi,windows-7,C++,Winapi,Windows 7,对于某些键,它适用于某些键,而对于某些键则不适用:例如,它适用于“Adobe”、“TrendMicro”、“CheckPoint”、“RegisteredApplications”,但不适用于“7-Zip”、“RTLSetup”、“Sonic”、“TeamSpeak 3 Client” 我现在没主意了,有人能指出哪里不对劲吗 编辑:我已经用“(默认)”值和其他值检查了代码,对于不起作用的键,它永远不会通过*“if(retValue==ERROR\u SUCCESS)”*检查,我总是会得到“指定文

对于某些键,它适用于某些键,而对于某些键则不适用:例如,它适用于“Adobe”、“TrendMicro”、“CheckPoint”、“RegisteredApplications”,但不适用于“7-Zip”、“RTLSetup”、“Sonic”、“TeamSpeak 3 Client”

我现在没主意了,有人能指出哪里不对劲吗

编辑:我已经用“(默认)”值和其他值检查了代码,对于不起作用的键,它永远不会通过*“if(retValue==ERROR\u SUCCESS)”*检查,我总是会得到“指定文件未找到”错误。对于其工作的键,它通过“*if(retValue==ERROR\u SUCCESS)*”检查并返回值(如果它存在),如果它不存在,它只显示错误消息“Specified file not found”


编辑2:我再次检查:它所适用的键似乎在软件下的“Wow6432Node”子键中有相应的克隆。。。六羟甲基三聚氰胺六甲醚。。。那么如何使其工作呢?

您可以指定标志::

  • 如果您想从应用程序访问WOW6432节点密钥,即32位密钥,请在“RegOpenKeyEx的“samDesired”参数中使用“
  • 如果您想从应用程序访问普通密钥,即64位密钥,请在RegOpenKeyEx的“samDesired”参数中选择“KEY\u WOW64\u 64KEY

  • 注意:@WhozCraig已经通过适当的链接在评论中澄清了您的疑问。如果他回答,一定要接受他的回答而不是我的。

    你正在经历什么行为?您是否手动检查了后一个条目是否有数据?首先,您的应用程序是64位还是32位,其次,当您的32位应用程序查找32位关联的应用程序时,或者您的64位应用程序查找64位关联的应用程序时,您是否注意到您的算法“工作”有所不同,但当您混合使用这两种方法时,似乎不工作?如果是这样,谷歌@bash.d更新了原来的问题。@WhozCraig我的应用程序是32位的,在管理员许可下工作,我测试的所有密钥都是64位的应用程序。我再次检查,它的工作键似乎在软件下的“Wow6432Node”子键中有相应的克隆。。。六羟甲基三聚氰胺六甲醚。。。那我怎么得到它呢working@StudentX点击我的评论中的,开始阅读,特别是阅读关于使用标志访问“另一面”。
    string ts3 = GetSZValueUnique( HKEY_LOCAL_MACHINE, "SOFTWARE\\TeamSpeak 3 Client\\", "" );
    if ( !ts3.empty() )
        MessageBox( 0, ts3.c_str(), "GetSZValueUnique", 0 );