现在的位置: 首页 > 自动控制 > 工业·编程 > 正文

开机自动运行

2012-08-20 06:21 工业·编程 ⁄ 共 573字 ⁄ 字号 暂无评论

BOOL SetAutoRun(CString strPath)//开机自动运行
{
CString str;
HKEY hRegKey;
BOOL bResult;
str=_T(“Software//Microsoft//Windows//CurrentVersion//Run”);
if(RegOpenKey(HKEY_LOCAL_MACHINE, str, &hRegKey) != ERROR_SUCCESS)
bResult=FALSE;
else
{
_splitpath(strPath.GetBuffer(0),NULL,NULL,str.GetBufferSetLength(MAX_PATH+1),NULL);
strPath.ReleaseBuffer();
str.ReleaseBuffer();
if(::RegSetValueEx( hRegKey,
str,
0,
REG_SZ,
(CONST BYTE *)strPath.GetBuffer(0),
strPath.GetLength() ) != ERROR_SUCCESS)
bResult=FALSE;
else
bResult=TRUE;
strPath.ReleaseBuffer();
}
return bResult;
}
其中strPath参数表示要设置为自运行的程序的绝对路径。当设置成功时返回true,否则返回false

给我留言

留言无头像?