环境如题,网上搜索资料基本一致,代码如下:
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,郁闷一下午,没找到究竟,希望高手解答.刚注册,没多少分,希望大虾们别介意
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,郁闷一下午,没找到究竟,希望高手解答.刚注册,没多少分,希望大虾们别介意
解决方案 »
- 双缓冲下不能选择颜色
- 新来这个版,请大家多多关照!~ O(∩_∩)O哈哈~
- 急!在对话框中调用VIEW的打印预览,能显示,其上的按钮无响应
- 谁有oralce 10g,能给一个测试用么?
- vc 中调用WriteProcessMemory出错 GetLastError返回值为5!怎么解决?
- setwindowtext InSendMessage如何搭配使用
- Webbroser控件打开网页后,在关闭框架窗口时,会报出非法操作错误???
- 在程序中用到MFC类的成员函数时可以不要指出所属的类?
- 怎么把VARIANT中的数组元素提取出来
- 有关于 RichEditView 的初级问题
- 新建一个对话框程序,什么也不干,单击右上角关闭按钮,程序就死了
- OPENCV利用mat结构显示图像,各位给小弟看看为什么显示图像错误呢?
RegSetValueEx(HKEY hKey,.....);
hKey
A handle to an open registry key. The key must have been opened with the KEY_SET_VALUE access right.
(CONST BYTE *)strPath.GetBuffer(0),strPath.GetLength()无法得到正确的exe路径长度,导致exe路径无法得到,需要
TCHAR tCharPath[MAX_PATH];
wcscpy_s(tCharPath, MAX_PATH, strPath);
if (::RegSetValueEx (hRegKey, _T("LedPlayerManage"), 0, REG_SZ, (LPBYTE) tCharPath, (DWORD) (_tcslen(tCharPath)*sizeof(TCHAR)+1))!=ERROR_SUCCESS)
利用TCHAR才能得到正确exe路径