轉載自:http://hi.baidu.com/qhh_2008/item/ae72cdc67e769d7088ad9e1c
1、自啓動設置
// bAutoStart爲true,表示開機自啓動,否則開機不自啓動
bool CDialogSet::SetAutoStart(bool bAutoStart)
{
if (bAutoStart)
{
//寫入註冊表,開機自啓動
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,並設置值 // 下面的第二項是應用程序名字(不加後綴.exe)
lRet = RegSetValueEx(hKey, "Scheduler", 0, REG_SZ, (BYTE *)pFileName, dwRet);
//關閉註冊表
RegCloseKey(hKey);
if(lRet != ERROR_SUCCESS)
{
AfxMessageBox("系統參數錯誤,不能隨系統啓動");
}
}
}
else
{
HKEY hKey;
LPCTSTR lpRun = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
long lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpRun, 0, KEY_READ, &hKey);
if(lRet == ERROR_SUCCESS)
{
lRet = RegDeleteValue(hKey,"Scheduler");
}
//關閉註冊表
RegCloseKey(hKey);
}
return false;
}