gpt4 book ai didi

c++ - 将 DWORD 从 HKCU 复制到 HKLM

转载 作者:行者123 更新时间:2023-11-30 04:15:30 25 4
gpt4 key购买 nike

将注册表值从 HKCU 复制到 HKLM 时出现问题。它是一个 DWORD,我正在使用此代码枚举所有 key 并在我安装的特定时间复制它们。

HRESULT hr = S_OK;
UINT er = ERROR_SUCCESS;
HKEY hKey;
char szProductKey[MAX_PATH], lszValue[MAX_PATH];
TCHAR achKey[MAX_KEY_LENGTH], achClass[MAX_PATH] = TEXT(""), achValue[MAX_VALUE_NAME];
DWORD cbName, cchClassName = MAX_PATH, cSubKeys=0, cbMaxSubKey, cchMaxClass, cValues, cchMaxValue, cbMaxValueData, cbSecurityDescriptor;
FILETIME ftLastWriteTime;
PHKEY phkResult = NULL;
DWORD i, retCode, cchValue = MAX_VALUE_NAME,dwType=REG_SZ,dwSKeyValueSize,dwSize=255;

hr = WcaInitialize(hInstall, "ReadTempRegKey");
ExitOnFailure(hr, "Failed to initialize");

WcaLog(LOGMSG_STANDARD, "Initialized.");

Orc_Reg_Sub_LM_CU();

sprintf_s(szProductKey, "SOFTWARE\\M\\%s",Orc_Get_Product_Name());
WcaLog(LOGMSG_STANDARD , szProductKey);
if( RegOpenKeyEx( HKEY_CURRENT_USER,
szProductKey,
0,
KEY_READ,
&hKey) == ERROR_SUCCESS
)
{
//Get the class name and the value count.
retCode = RegQueryInfoKey(
hKey, // key handle
achClass, // buffer for class name
&cchClassName, // size of class string
NULL, // reserved
&cSubKeys, // number of subkeys
&cbMaxSubKey, // longest subkey size
&cchMaxClass, // longest class string
&cValues, // number of values for this key
&cchMaxValue, // longest value name
&cbMaxValueData, // longest value data
&cbSecurityDescriptor, // security descriptor
&ftLastWriteTime); // last write time

// Enumerate the subkeys, until RegEnumKeyEx fails.

if (cSubKeys)
{
for (i=0; i<cSubKeys; i++)
{
cbName = MAX_KEY_LENGTH;
retCode = RegEnumKeyEx(hKey, i,
achKey,
&cbName,
NULL,
NULL,
NULL,
&ftLastWriteTime);
}
}

//Enumerate the key values.

if (cValues)
{
for (i=0, retCode=ERROR_SUCCESS; i<cValues; i++)
{
cchValue = MAX_VALUE_NAME;
achValue[0] = '\0';
retCode = RegEnumValue(hKey, i,
achValue,
&cchValue,
NULL,
NULL,
NULL,
NULL);

if (retCode == ERROR_SUCCESS )
{
DWORD dwSize = sizeof(lszValue);
retCode = RegQueryValueEx(hKey, achValue, NULL, &dwType,(LPBYTE)&lszValue, &dwSize);
if (retCode == ERROR_SUCCESS)
{

Orc_Reg_Stop_LM_CU();
dwSKeyValueSize = strlen((char*) lszValue);
Orc_RegValue(HKEY_LOCAL_MACHINE,
"SOFTWARE\\M\\Orchestrator",
KEY_SET_VALUE,
achValue,
&dwType,
(unsigned char *)lszValue,
&dwSKeyValueSize);

}
}
}
}
}

复制后注册表的值是正确的,但数据显示 无效的 dword 32 位值 有谁知道会导致这种情况的原因吗?

谢谢

最佳答案

您收到 invalid dword 32-bit value 消息,因为传递给 Orc_RegValue() 的最后一个参数不正确。 REG_DWORD 数据类型的正确值为 sizeof(DWORD)

尝试传递 dwSize 而不是 dwSKeyValueSize

                Orc_RegValue(HKEY_LOCAL_MACHINE,
"SOFTWARE\\M\\Orchestrator",
KEY_SET_VALUE,
achValue,
&dwType,
(unsigned char *)lszValue,
&dwSize);

或者你可以试试

   dwSKeyValueSize = dwSize;

代替

   dwSKeyValueSize = strlen((char*) lszValue);

关于c++ - 将 DWORD 从 HKCU 复制到 HKLM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18271169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com