//--------------------------------------------------------------------------- #include #pragma hdrstop #include "StartUp.h" //--------------------------------------------------------------------------- #pragma package(smart_init) // Registry¿¡ ½ÃÀÛÇÁ·Î±×·¥À¸·Î µî·ÏÇÑ´Ù. // exam : ResigterStartUp("Project1", false, "c:\test\Project1.exe"); // ¼º°øÇÒ °æ¿ì 0À» ¹ÝȯÇÑ´Ù. HRESULT RegisterStartUp(const char *pTitle, bool bRunOnce, const char *pCmdLine) { char szSubKey[_MAX_PATH]; HKEY hKey; LONG lRes; strcpy(szSubKey, "Software\\Microsoft\\Windows\\CurrentVersion\\Run"); if (bRunOnce) strcat(szSubKey, "Once"); lRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szSubKey, 0, KEY_ALL_ACCESS, &hKey); if (lRes != ERROR_SUCCESS) return (HRESULT)lRes; char szData[_MAX_PATH]; if (pCmdLine == NULL) strcpy(szData, Application->ExeName.c_str()); else strcpy(szData, pCmdLine); lRes = RegSetValueEx(hKey, pTitle, 0, REG_SZ, szData, strlen(szData) + 1); if (lRes != ERROR_SUCCESS) return (HRESULT)lRes; return 0; } // Registry¿¡ ½ÃÀÛÇÁ·Î±×·¥À¸·Î µî·ÏµÈ ºÎºÐ(pTitle)À» »èÁ¦ÇÑ´Ù. // exam : ResigterStartUp("Project1", false); // ¼º°øÇÒ °æ¿ì 0À» ¹ÝȯÇÑ´Ù. HRESULT UnregisterStartUp(const char *pTitle, bool bRunOnce) { char szSubKey[_MAX_PATH]; HKEY hKey; LONG lRes; strcpy(szSubKey, "Software\\Microsoft\\Windows\\CurrentVersion\\Run"); if (bRunOnce) strcat(szSubKey, "Once"); lRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szSubKey, 0, KEY_ALL_ACCESS, &hKey); if (lRes != ERROR_SUCCESS) return (HRESULT)lRes; char szData[_MAX_PATH]; lRes = RegDeleteValue(hKey, pTitle); if (lRes != ERROR_SUCCESS) return (HRESULT)lRes; return 0; }