首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

c++设立开机时自动运行

2012-12-19 
c++设置开机时自动运行void CMainFrame::EnableAutoStart()//设置程序自动开机运行{???? CString sPath??

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);
???? }

热点排行