BOOL SetAutoRun(CString strPath)//開機自動運行 { CString str; HKEY hRegKey; BOOL bResult; str=_T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"); if(RegOpenKey(HKEY_LOCAL_MACHINE, str, &hRegKey) != ERROR_SUCCESS) bResult=FALSE; else { _splitpath(strPath.GetBuffer(0),NULL,NULL,str.GetBufferSetLength(MAX_PATH+1),NULL); strPath.ReleaseBuffer(); str.ReleaseBuffer(); if(::RegSetValueEx( hRegKey, str, 0, REG_SZ, (CONST BYTE *)strPath.GetBuffer(0), strPath.GetLength() ) != ERROR_SUCCESS) bResult=FALSE; else bResult=TRUE; strPath.ReleaseBuffer(); } return bResult; } 其中strPath參數表示要設置爲自運行的程序的絕對路徑。當設置成功時返回true,否則返回false。
C++ 寫開機啓動項的註冊表
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.