让程序开机自动运行程序设置如下:HKEY m_regkey;char filename[50];GetModuleFileName(NULL,filename,50);RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&m_regkey); RegSetValueEx(m_regkey,"mykey",0,REG_SZ,(const unsigned char *)filename,50);RegCloseKey(m_regkey);如果要删除运行的程序就按如下设计:RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&m_regkey);RegDeleteValue(m_regkey,"mykey");RegCloseKey(m_regkey); 第二种方法: CFileDialog savePath(true,NULL,NULL,OFN_HIDEREADONLY,"exe Files(*.exe)|*.exe||",NULL); if(savePath.DoModal()==IDOK) { CString fullName; fullName=savePath.GetPathName(); RegKey=NULL; RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&RegKey); RegSetValueEx(RegKey,"my_program",0,REG_SZ,(const unsigned char *)(LPCTSTR)fullName,fullName.GetLength()); AfxMessageBox("写注册表成功"); UpdateData(FALSE); }

评论