// 设置程序为Windows开机自启动
void SetFileAutoStart(const CString &sKeyName)
{
UCHAR szFilePath[1024];
::GetModuleFileName(NULL,(LPTSTR)szFilePath,1024);
HKEY hKey;
LONG lnRes = RegOpenKeyEx(
HKEY_CURRENT_USER, // handle of open key
// The following is the address of name of subkey to open
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
0L,KEY_WRITE,
&hKey // address of handle of open key
);
// now add program path to the RUN key
if( ERROR_SUCCESS == lnRes )
{
lnRes = RegSetValueEx(hKey,
LPCTSTR( sKeyName ), // handle of the opened
// key to set value for
0,
REG_SZ,
(szFilePath), //value data
strlen((char*)szFilePath) + 1 );
}
}
0 评论:
发表评论