开机启动

设置开机启动
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("打开开机启动成功"); } }
取消开机启动
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("关闭开机启动成功");   
                    }  

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


 

posted @ 2013-12-30 15:54  风刮过冷  阅读(184)  评论(0编辑  收藏  举报