开机自启动写入注册表失败

tixisong 2014-12-15 01:14:04

// 程序开机启动写入注册表
bool CSlitMachineApp::WriteKEY()
{
long lRet;
DWORD dwDisposition;
HKEY hAppKey = NULL;
LPCTSTR lpRun = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run");

lRet = RegCreateKeyEx(HKEY_LOCAL_MACHINE, lpRun, 0, NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE, NULL, &hAppKey, &dwDisposition);

if (lRet == ERROR_SUCCESS)
{
TCHAR pFileName[MAX_PATH] = { 0 };
//得到程序自身的全路径
DWORD dwRet = GetModuleFileName(NULL, pFileName, MAX_PATH);
//添加一个子key,并设置值
lRet = RegSetValueEx(hAppKey, _T("DS"), 0, REG_SZ, (BYTE*)pFileName, dwRet );
//关闭注册表
RegCloseKey(hAppKey);
}
return true;
}

RegSetValueEx返回为0,没有错误,但在注册表中没有写进去。
...全文
309 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
tixisong 2014-12-16
  • 打赏
  • 举报
回复
引用 1 楼 lsq19871207 的回复:
你的操作系统是64位,而你的这个程序是Win32位的吧? 32-bit and 64-bit Application Data in the Registry 34 out of 58 rated this helpful - Rate this topic On 64-bit Windows, portions of the registry entries are stored separately for 32-bit application and 64-bit applications and mapped into separate logical registry views using the registry redirector and registry reflection, because the 64-bit version of an application may use different registry keys and values than the 32-bit version. There are also shared registry keys that are not redirected or reflected. The parent of each 64-bit registry node is the Image-Specific Node or ISN. The registry redirector transparently directs an application's registry access to the appropriate ISN subnode. Redirection subnodes in the registry tree are created automatically by the WOW64 component using the name Wow6432Node. As a result, it is essential not to name any registry key you create Wow6432Node. The KEY_WOW64_64KEY and KEY_WOW64_32KEY flags enable explicit access to the 64-bit registry view and the 32-bit view, respectively. For more information, see Accessing an Alternate Registry View. To disable and enable registry reflection for a particular key, use the RegDisableReflectionKey and RegEnableReflectionKey functions. Applications should disable reflection only for the registry keys that they create and not attempt to disable reflection for the predefined keys such as HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER. To determine which keys are on the reflection list, use the RegQueryReflectionKey function. 修改: lRet = RegCreateKeyEx(HKEY_LOCAL_MACHINE, lpRun, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hAppKey, &dwDisposition); --------------------------------------------------------------------------------------->

lRet = RegCreateKeyEx(HKEY_LOCAL_MACHINE, lpRun, 0, NULL,
        REG_OPTION_NON_VOLATILE, 
        KEY_WRITE|KEY_WOW64_64KEY, NULL, &hAppKey, &dwDisposition);
//or:
//lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,lpRun,0,KEY_READ|KEY_WRITE|KEY_WOW64_64KEY,&hAppKey);
果然是这样子,结贴
信阳毛尖 2014-12-15
  • 打赏
  • 举报
回复
你的操作系统是64位,而你的这个程序是Win32位的吧? 32-bit and 64-bit Application Data in the Registry 34 out of 58 rated this helpful - Rate this topic On 64-bit Windows, portions of the registry entries are stored separately for 32-bit application and 64-bit applications and mapped into separate logical registry views using the registry redirector and registry reflection, because the 64-bit version of an application may use different registry keys and values than the 32-bit version. There are also shared registry keys that are not redirected or reflected. The parent of each 64-bit registry node is the Image-Specific Node or ISN. The registry redirector transparently directs an application's registry access to the appropriate ISN subnode. Redirection subnodes in the registry tree are created automatically by the WOW64 component using the name Wow6432Node. As a result, it is essential not to name any registry key you create Wow6432Node. The KEY_WOW64_64KEY and KEY_WOW64_32KEY flags enable explicit access to the 64-bit registry view and the 32-bit view, respectively. For more information, see Accessing an Alternate Registry View. To disable and enable registry reflection for a particular key, use the RegDisableReflectionKey and RegEnableReflectionKey functions. Applications should disable reflection only for the registry keys that they create and not attempt to disable reflection for the predefined keys such as HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER. To determine which keys are on the reflection list, use the RegQueryReflectionKey function. 修改: lRet = RegCreateKeyEx(HKEY_LOCAL_MACHINE, lpRun, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hAppKey, &dwDisposition); --------------------------------------------------------------------------------------->

lRet = RegCreateKeyEx(HKEY_LOCAL_MACHINE, lpRun, 0, NULL,
        REG_OPTION_NON_VOLATILE, 
        KEY_WRITE|KEY_WOW64_64KEY, NULL, &hAppKey, &dwDisposition);
//or:
//lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,lpRun,0,KEY_READ|KEY_WRITE|KEY_WOW64_64KEY,&hAppKey);
随着通信电子技术的迅速发展,信息技术给家居行业产生了深远的影响,家居环境的智能化监控已经成为智能家居的一个重要的发展方向。人们逐渐对自己的生活提出一种更高的要求,他们需要一种智能化、可交互,并且融合现代创新科技的产品来改善他们的生活环境,使他们生活更加安全、舒适、便捷、智能。本文根据智能家居的发展背景和研究现状,并且从实用性和可行性角度出发,研究设计了一种基于STM32单片机的智能家居系统。该系统由一个多功能综合的技术系统组成,各个多功能子系统间具有协同配合能力。基于STM32单片机实现的功能子系统包括:智能温度检测,智能湿度检测,智能烟雾/火灾检测智能检测,无线传输,人机交互机构,风扇调节,报警模块。 整个系统分为前端51单片机采集板和后端STM32单片机接收板。 采集板使用DHT11温湿度传感器、MQ烟雾传感器完成室内家居环境的采集。然后通过nRFL24L01将采集到的数据发送给后端。接收板使用LCD1602完成数据显示、使用蜂鸣器模块报警,使用风扇驱动模块调节室内家居环境。本文完成了智能家居控制系统前端、后端软硬件的设计,使用Altium designer绘制了电路原理图,使用Keil C完成了51单片机和STM32单片机的编程与调试。 最后,对本文设计的基于STM32的智能家居控制系统进行部署调试。试验结果表明,该系统可成功应用在智能家居环境检测调节和火灾安全防护的领域,可提高家居生活智能化水平。

16,550

社区成员

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

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

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