|
CString StrFilter="Executable files (*.exe)|*.exe|All files (*.*)|*.*||";
CFileDialog Dlg(TRUE,NULL,NULL,NULL,StrFilter,this);
if(Dlg.DoModal()==IDCANCEL)
return;
HKEY hKey;
LPCTSTR StrKey="Software\\Microsoft\\Windows\\CurrentVersion\\Run";
if(ERROR_SUCCESS==::RegOpenKeyEx(HKEY_CURRENT_USER,StrKey,NULL,KEY_ALL_ACCESS,&hKey))
{
CString Value=Dlg.GetPathName();
LPCSTR KeyValue=Dlg.GetFileTitle();
if(ERROR_SUCCESS==::RegSetValueEx(hKey,(LPCTSTR)KeyValue,0,REG_SZ,
(BYTE *)(LPCSTR)Value,strlen(Value)+1))
{
AfxMessageBox("Set the program to run automatically when the system starts!");
}
//::RegDeleteValue(hKey,(LPCTSTR)KeyValue);
::RegCloseKey(hKey);
} |
|