c++设置开机时自动运行
void CMainFrame::EnableAutoStart()//设置程序自动开机运行
{
???? CString sPath;
???? int nPos;
???? HKEY RegKey;
???? GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
???? sPath.ReleaseBuffer();
???? nPos=sPath.ReverseFind('\\');
???? sPath=sPath.Left(nPos);
???? CString lpszFile=sPath+"\\YbkDemo.exe";
???? CFileFind fFind;
???? BOOL bSuccess;
???? bSuccess=fFind.FindFile(lpszFile);
???? fFind.Close();
???? if(bSuccess)
???? {
???????? CString fullName;
???????? fullName=lpszFile;
???????? RegKey=NULL;
???????? RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&RegKey);
???????? RegSetValueEx(RegKey,"彭水白云监控系统",0,REG_SZ,(const unsigned char*)(LPCTSTR)fullName,fullName.GetLength());
???????? this->UpdateData(FALSE);
???? }
???? else
???? {
???????? ::AfxMessageBox("没找到执行程序,自动运行失败");
???????? exit(0);
???? }