增刪啟動項

weixin_34304013發表於2011-04-17

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; } CString GetMyPath() { CString strPath; GetModuleFileName(NULL,strPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH); strPath.ReleaseBuffer(); return strPath; } BOOL DelSetUp(CString strPath) { CString str; HKEY hRegKey; BOOL bResult; char filename[_MAX_FNAME]; 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,filename,NULL); if (::RegDeleteValue(hRegKey,filename)!=ERROR_SUCCESS) { bResult=FALSE; } else bResult=true; } return bResult; } 

相關文章