设置注册表键值SetRegisterValue
BOOL SetRegisterValue(HKEY key, CHAR* path, CHAR* name, std::string& strAccessStream)
{
HKEY hKey = NULL;
BOOL isok = FALSE;
do
{
long lRet = RegCreateKeyExA(key, path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS | KEY_WOW64_64KEY, NULL, &hKey, NULL);
if (ERROR_SUCCESS != lRet)
{
break;
}
lRet = RegSetValueExA(hKey, name, 0, REG_SZ, (LPBYTE)strAccessStream.c_str(), (ULONG)strAccessStream.size());
if (ERROR_SUCCESS != lRet)
{
break;
}
isok = TRUE;
} while (0);
if (hKey)
{
RegCloseKey(hKey);
}
return isok;
}
std::string strAccessStream;
SetRegisterValue(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\MyPath", "UserKey", strAccessStream);
随手分享,手有余香