MFC设置开机启动

来源:互联网 发布:什么是程序员考试 编辑:程序博客网 时间:2024/06/04 18:06

设置开机启动                        HKEY hKey; //找到系统的启动项 LPCTSTR lpRun = "Software\\Microsoft\\Windows\\CurrentVersion\\Run"; //打开启动项Key long lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpRun, 0, KEY_WRITE, &hKey); if(lRet == ERROR_SUCCESS) { char pFileName[MAX_PATH] = {0}; //得到程序自身的全路径 DWORD dwRet = GetModuleFileName(NULL, pFileName, MAX_PATH); //添加一个子Key,并设置值 // 下面的"test"是应用程序名字(不加后缀.exe)lRet = RegSetValueEx(hKey, "test", 0, REG_SZ, (BYTE *)pFileName, dwRet); //关闭注册表 RegCloseKey(hKey); if(lRet != ERROR_SUCCESS) { AfxMessageBox("系统参数错误,不能完成开机启动设置"); } else{AfxMessageBox("打开开机启动成功"); }isrun = 1;} 

取消开机启动HKEY hKey; //找到系统的启动项 LPCTSTR lpRun = "Software\\Microsoft\\Windows\\CurrentVersion\\Run"; //打开启动项Key long lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpRun, 0, KEY_WRITE, &hKey); if(lRet == ERROR_SUCCESS) { char pFileName[MAX_PATH] = {0}; //得到程序自身的全路径 DWORD dwRet = GetModuleFileName(NULL, pFileName, MAX_PATH); //添加一个子Key,并设置值 // 下面的"test"是应用程序名字(不加后缀.exe)lRet = RegDeleteValue(hKey, "test");//关闭注册表 RegCloseKey(hKey); if(lRet != ERROR_SUCCESS) { AfxMessageBox("系统参数错误,不能完成取消开机启动设置"); } else{AfxMessageBox("关闭开机启动成功"); }<SPAN style="WHITE-SPACE: pre"></SPAN>}


参考原文:http://blog.csdn.net/leesaiya/article/details/7398160