SetAutoRun(_T("Software\\Microsoft\\Windows\\CurrentVersion\\Run")) ;
void CScreenLockDlg::SetAutoRun(CString filePath)
{HKEY hKey;
//打开启动项Key
long lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, filePath, 0, KEY_WRITE, &hKey);
if(lRet == ERROR_SUCCESS)
{
char pFileName[MAX_PATH] = {0};
//获取程序自身的全路径
DWORD dwRet = GetModuleFileName(NULL, (LPWCH)pFileName, MAX_PATH);
CString Param = (LPCTSTR)pFileName;
Param += _T(" screenlock") ; //给启动项添加参数
char *p = (LPSTR)(LPCTSTR)Param;
//添加一个子Key,并设置值,"ScreenLock"是应用程序名字
lRet = RegSetValueEx(hKey,_T("ScreenLock") , 0, REG_SZ, (BYTE *)p, lstrlenW((LPCWSTR)p) * sizeof(WCHAR));
RegCloseKey(hKey); //关闭注册表
if(lRet != ERROR_SUCCESS)
{
AfxMessageBox(_T("系统参数错误,不能完成开机启动设置"));
}
}
}