为什么重启机器后,我写的注册表信息就丢失了?

newhero 2003-08-26 10:09:11
CRegistry reg;
BOOL bReturn;
DWORD dw=10,dw2;
CString s;
int i=1,j;
bReturn=reg.Open ("Software\0");
bReturn= reg.CreateKey ("vckbase\0");
bReturn=reg.Open("vckbase\0");
bReturn= reg.Write ("name","hahahaha");
// bReturn=reg.Write("name","erio");
bReturn= reg.Write ("age",i);
bReturn= reg.Write ("sarary",dw);
bReturn=reg.Read ("name",&s);
reg.Close();
AfxMessageBox(s);
...全文
166 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
newhero 2003-08-26
  • 打赏
  • 举报
回复
我看的2001年4月的MSDN
newhero 2003-08-26
  • 打赏
  • 举报
回复
可能是我们看的MSDN的版本不同,我的MSDN写到
dwOptions
[in] Ignored; set to 0 to ensure compatibility with future versions of Windows CE.
就这么一点.
曾经的猎狐 2003-08-26
  • 打赏
  • 举报
回复
dwOptions
[in] Specifies special options for the key. This parameter can be one of the following values. Value Meaning
REG_OPTION_NON_VOLATILE This key is not volatile; this is the default. The information is stored in a file and is preserved when the system is restarted. The RegSaveKey function saves keys that are not volatile.
REG_OPTION_VOLATILE Windows NT/2000/XP: All keys created by the function are volatile. The information is stored in memory and is not preserved when the corresponding registry hive is unloaded. For HKEY_LOCAL_MACHINE, this occurs when the system is shut down. For registry keys loaded by the RegLoadKey function, this occurs when the corresponding RegUnloadKey is performed. The RegSaveKey function does not save volatile keys. This flag is ignored for keys that already exist.
Windows 95/98/Me: This value is ignored. If REG_OPTION_VOLATILE is specified, the RegCreateKeyEx function creates nonvolatile keys and returns ERROR_SUCCESS.

REG_OPTION_BACKUP_RESTORE Windows NT/2000/XP: If this flag is set, the function ignores the samDesired parameter and attempts to open the key with the access required to backup or restore the key. If the calling thread has the SE_BACKUP_NAME privilege enabled, the key is opened with ACCESS_SYSTEM_SECURITY and KEY_READ access. If the calling thread has the SE_RESTORE_NAME privilege enabled, the key is opened with ACCESS_SYSTEM_SECURITY and KEY_WRITE access. If both privileges are enabled, the key has the combined accesses for both privileges.


MSDN上的原封不动的给你拿来了,是你自己没有查清楚
曾经的猎狐 2003-08-26
  • 打赏
  • 举报
回复
dwOptions
[in] Specifies special options for the key. This parameter can be one of the following values. Value Meaning
REG_OPTION_NON_VOLATILE This key is not volatile; this is the default. The information is stored in a file and is preserved when the system is restarted. The RegSaveKey function saves keys that are not volatile.
REG_OPTION_VOLATILE Windows NT/2000/XP: All keys created by the function are volatile. The information is stored in memory and is not preserved when the corresponding registry hive is unloaded. For HKEY_LOCAL_MACHINE, this occurs when the system is shut down. For registry keys loaded by the RegLoadKey function, this occurs when the corresponding RegUnloadKey is performed. The RegSaveKey function does not save volatile keys. This flag is ignored for keys that already exist.
Windows 95/98/Me: This value is ignored. If REG_OPTION_VOLATILE is specified, the RegCreateKeyEx function creates nonvolatile keys and returns ERROR_SUCCESS.

REG_OPTION_BACKUP_RESTORE Windows NT/2000/XP: If this flag is set, the function ignores the samDesired parameter and attempts to open the key with the access required to backup or restore the key. If the calling thread has the SE_BACKUP_NAME privilege enabled, the key is opened with ACCESS_SYSTEM_SECURITY and KEY_READ access. If the calling thread has the SE_RESTORE_NAME privilege enabled, the key is opened with ACCESS_SYSTEM_SECURITY and KEY_WRITE access. If both privileges are enabled, the key has the combined accesses for both privileges.


MSDN上的原封不动的给你拿来了,是你自己没有查清楚
newhero 2003-08-26
  • 打赏
  • 举报
回复
非常感谢,已经成功了,打算给你100分
不过再问一个问题,我在MSDN上都没有查到用什么参数,你是怎么知道的?
bcpl 2003-08-26
  • 打赏
  • 举报
回复
说错了,REG_OPTION_VOLATILE才会重启即丢失,REG_OPTION_NON_VOLATILE为永久保存。
newhero 2003-08-26
  • 打赏
  • 举报
回复
请问bcpl(戒烟直到五颗星) 应该用什么参数呢?我在MSDN没有查到
感谢!!
bcpl 2003-08-26
  • 打赏
  • 举报
回复
如果RegCreateKeyEx用了REG_OPTION_NON_VOLATILE参数则有此现象
newhero 2003-08-26
  • 打赏
  • 举报
回复
WRITE函数如下
BOOL CRegistry::Write(LPCTSTR lpValueName, LPCTSTR lpValue)
{
ASSERT(m_hKey);
ASSERT(lpValueName);
ASSERT(lpValue);

long lReturn=RegSetValueEx(m_hKey,lpValueName,0L,REG_SZ,(const BYTE *) lpValue,strlen(lpValue)+1);

if(lReturn==ERROR_SUCCESS)
return TRUE;

return FALSE;

}

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧