首页 > 编程语言 > 详细

mfc 设置开机启动

时间:2014-10-21 13:42:51      阅读:301      评论:0      收藏:0      [点我收藏+]
 1 CButton* pBtn = (CButton*)GetDlgItem(IDC_CHECK_AUTO);
 2     int state = pBtn->GetCheck();
 3     HKEY hKey;   
 4     //找到系统的启动项   
 5     LPCTSTR lpRun = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";   
 6     //打开启动项Key   
 7     long lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpRun, 0, KEY_WRITE, &hKey);   
 8     if(lRet == ERROR_SUCCESS)   
 9     {   
10         char pFileName[MAX_PATH] = {0};   
11         //得到程序自身的全路径   
12         DWORD dwRet = GetModuleFileName(NULL, pFileName, MAX_PATH);   
13 
14     if (state == 1)
15     {
16         //添加一个子Key,并设置值 // 下面的"test"是应用程序名字(不加后缀.exe)  
17         lRet = RegSetValueEx(hKey, "client", 0, REG_SZ, (BYTE *)pFileName, dwRet); //开机启动
18     }else if ( state == 0)
19     {
20         //添加一个子Key,并设置值 // 下面的"test"是应用程序名字(不加后缀.exe)  
21         lRet = RegDeleteValue(hKey, "client"); //开机不启动
22     }
23 
24     //关闭注册表   
25     RegCloseKey(hKey);   
26     if(lRet != ERROR_SUCCESS)   
27     {   
28         AfxMessageBox("系统参数错误,不能完成开机启动设置");   
29     }    
30     }   

 

mfc 设置开机启动

原文:http://www.cnblogs.com/kingbin/p/4040115.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!