参考http://support.microsoft.com/kb/97597/zh-cn
/*
@设置开机自启动
@strUser,用户名
@strPass,密码
@strAutoAdminLogon,当该值为1时自动登录,0取消
@return,成功返回TRUE,否则返回FALSE
*/
BOOL SetWindowAutoLogin(LPCTSTR strUser,LPCTSTR strPass,LPCTSTR strAutoAdminLogon)
{
HKEY hKey;
LONG ntStatus = RegOpenKey(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"),&hKey);
if (ERROR_SUCCESS != ntStatus)
return FALSE;
ntStatus = RegSetValueEx(hKey,_T("DefaultUserName"),0,REG_SZ,(CONST BYTE*)strUser,_tcslen(strUser)*sizeof(TCHAR));
if (ERROR_SUCCESS != ntStatus)
{
RegCloseKey(hKey);
return FALSE;
}
ntStatus = RegSetValueEx(hKey,_T("DefaultPassword"),0,REG_SZ,(CONST BYTE*)strPass,_tcslen(strPass)*sizeof(TCHAR));
if (ERROR_SUCCESS != ntStatus)
{
RegCloseKey(hKey);
return FALSE;
}
ntStatus = RegSetValueEx(hKey,_T("AutoAdminLogon"),0,REG_SZ,(CONST BYTE*)strAutoAdminLogon,_tcslen(strAutoAdminLogon)*sizeof(TCHAR));
if (ERROR_SUCCESS != ntStatus)
{
RegCloseKey(hKey);
return FALSE;
}
RegCloseKey(hKey);
return TRUE;
}