C RegLoadAppKey参数不正确
我正在尝试打开windows默认用户的注册表配置单元。我得到错误“参数无效”。我的代码如下:C RegLoadAppKey参数不正确,c,winapi,registry,C,Winapi,Registry,我正在尝试打开windows默认用户的注册表配置单元。我得到错误“参数无效”。我的代码如下: PHKEY loadDefaultHiveAppKey(){ PHKEY temporaryHKEY = 0; wchar_t * errorText = 0; //wchar_t * defaultProfileHiveFile = getDefaultUserProfileHive(); /* For debugging purpouses use a hardc
PHKEY loadDefaultHiveAppKey(){
PHKEY temporaryHKEY = 0;
wchar_t * errorText = 0;
//wchar_t * defaultProfileHiveFile = getDefaultUserProfileHive();
/* For debugging purpouses use a hardcoded path */
wchar_t * defaultProfileHiveFile = L"C:\\Users\\Default\\NTUSER.dat";
long returnCode = 0;
returnCode = RegLoadAppKey(
defaultProfileHiveFile,
temporaryHKEY,
KEY_ALL_ACCESS,
REG_PROCESS_APPKEY,
0
);
//free(defaultProfileHiveFile);
if(returnCode != ERROR_SUCCESS){
// http://stackoverflow.com/questions/455434/how-should-i-use-formatmessage-properly-in-c
FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
returnCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&errorText,
0,
NULL
);
printf("Failed to open registry hive!\n");
if(errorText != 0){
/* This prints "The Parameter is Incorrect" */
printf("%ls\n", errorText);
LocalFree(errorText);
errorText = NULL;
} else {
printf("Unknown reason!\n");
}
return 0;
}
return temporaryHKEY;
}
我的main基本上只是对前面方法的调用。这是的msdn文章。您的
phkResult
错误。如果你把它当作指向HKEY的指针来读会更清楚。您需要的是:
HKEY temporaryHKEY;
returnCode = RegLoadAppKey(
defaultProfileHiveFile,
&temporaryHKEY,
KEY_ALL_ACCESS,
REG_PROCESS_APPKEY,
0
);
wchar\u t*defaultProfileHiveFile
如何指向非宽字符串(无L
前缀)?好的,我尝试了,现在得到了cpp(106):错误C2664:'RegLoadAppKeyW':无法将参数2从'PHKEY*'转换为'PHKEY'1>,指向的类型不相关;转换需要重新解释\u cast、C样式cast或函数样式cast
哦,我好的,我看得很快,没有意识到您已将PHKEY更改为HKEY。成功了,现在我的访问被拒绝了,但我会尝试使用提升的权限执行它。这应该行得通。