win7 vs08 MFC 开机启动 RegSetValueEx返回5
环境如题,网上搜索资料基本一致,代码如下:
BOOL CGetTimeDlg::SetAutoRun(CString strPath)//开机自动运行,strPath为exe路径
{
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;
}
RegOpenKey(HKEY_LOCAL_MACHINE, str, &hRegKey)返回为0,表示成功,而
(::RegSetValueEx( hRegKey,str,0,REG_SZ,(CONST BYTE *)strPath.GetBuffer(0),strPath.GetLength() )返回为5,郁闷一下午,没找到究竟,希望高手解答.刚注册,没多少分,希望大虾们别介意