|
发表于 2020-10-12 12:45:01
|
显示全部楼层
CString StrFilter="可执行性文件(*.exe)|*.exe|所有文件(*.*)|*.*||";
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("设置程序为系统启动时自动运行!");
}
//::RegDeleteValue(hKey,(LPCTSTR)KeyValue);
::RegCloseKey(hKey);
} |
|