//開機啓動 int CMainWnd::CreateRun() { //添加如下代碼 HKEY hKey; char pFileName[MAX_PATH] = {0}; //獲得程序自身的全路徑 DWORD dwRet = GetModuleFileNameW(NULL, (LPWCH)pFileName, MAX_PATH); //找到系統的啓動項 LPCTSTR lpRun = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"); //打開啓動項Key long lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpRun, 0, KEY_WRITE, &hKey); if(lRet== ERROR_SUCCESS) { //添加註冊 RegSetValueEx(hKey, _T("UilibDemo"), 0,REG_SZ,(const BYTE*)(LPCSTR)pFileName, MAX_PATH); RegCloseKey(hKey); } return 0; } //取消開機啓動 int CMainWnd::DeleteRun() { //添加如下代碼 HKEY hKey; char pFileName[MAX_PATH] = {0}; //獲得程序自身的全路徑 DWORD dwRet = GetModuleFileNameW(NULL, (LPWCH)pFileName, MAX_PATH); //找到系統的啓動項 LPCTSTR lpRun = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"); //打開啓動項Key long lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpRun, 0, KEY_WRITE, &hKey); if(lRet== ERROR_SUCCESS) { //刪除註冊 RegDeleteValue(hKey,_T("UilibDemo")); RegCloseKey(hKey); } return 0; }
可經過命令:regedit 查看註冊表中的數據spa