Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.5 KiB

  1. #include "factoryp.h"
  2. #include <regstr.h>
  3. // [ComputerSettings]
  4. // AuditAdminAutoLogon=Yes
  5. // AutoLogon=Yes
  6. //
  7. #define REGSTR_PATH_WINNTLOGON TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon")
  8. #define DEFAULT_PWD TEXT("")
  9. #define DEFAULT_VALUE TEXT("1")
  10. BOOL AutoLogon(LPSTATEDATA lpStateData)
  11. {
  12. HKEY hKey;
  13. BOOL fReturn = FALSE;
  14. // Check the winbom to make sure they want the auto logon set.
  15. //
  16. if ( !DisplayAutoLogon(lpStateData) )
  17. {
  18. return TRUE;
  19. }
  20. // Now open the key and set the required values (see KB article Q253370).
  21. //
  22. if ( ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE, REGSTR_PATH_WINNTLOGON, &hKey) )
  23. {
  24. LPTSTR lpszUserName = AllocateString(NULL, ( GetSkuType() == VER_SUITE_PERSONAL ) ? IDS_OWNER : IDS_ADMIN);
  25. // The following three keys sets the auto admin logon after reboot. If the
  26. // password is empty string the AutoAdminLogon will be reset after reboot.
  27. //
  28. //
  29. if ( ( lpszUserName ) &&
  30. ( ERROR_SUCCESS == RegSetValueEx(hKey, TEXT("DefaultUserName"), 0, REG_SZ, (LPBYTE) lpszUserName, (lstrlen(lpszUserName) + 1) * sizeof(TCHAR)) ) &&
  31. ( ERROR_SUCCESS == RegSetValueEx(hKey, TEXT("DefaultPassword"), 0, REG_SZ, (LPBYTE) DEFAULT_PWD, (lstrlen(DEFAULT_PWD) + 1) * sizeof(TCHAR)) ) &&
  32. ( ERROR_SUCCESS == RegSetValueEx(hKey, TEXT("AutoAdminLogon"), 0, REG_SZ, (LPBYTE) DEFAULT_VALUE,(lstrlen(DEFAULT_VALUE) + 1) * sizeof(TCHAR)) ) &&
  33. ( ERROR_SUCCESS == RegDeleteValue(hKey, TEXT("AutoLogonCount")) ) )
  34. {
  35. fReturn = TRUE;
  36. }
  37. // Force so subsequent reboots won't reset AutoAdminLogon because of empty password.
  38. //
  39. // We don't need to force autologon for every reboot since the [ComputerSettings] section will be processed for
  40. // every boot.
  41. //
  42. // ( ERROR_SUCCESS == RegSetValueEx(hKey, TEXT("ForceAutoLogon"), 0, REG_SZ, (LPBYTE) DEFAULT_VALUE, (lstrlen(DEFAULT_VALUE) + 1) * sizeof(TCHAR)) )
  43. // Free the allocated user name (macro checks for NULL).
  44. //
  45. FREE(lpszUserName);
  46. // Close the registry key.
  47. //
  48. RegCloseKey(hKey);
  49. }
  50. return fReturn;
  51. }
  52. BOOL DisplayAutoLogon(LPSTATEDATA lpStateData)
  53. {
  54. return ( IniSettingExists(lpStateData->lpszWinBOMPath, INI_SEC_WBOM_SETTINGS, INI_KEY_WBOM_AUTOLOGON_OLD, INI_VAL_WBOM_YES) ||
  55. IniSettingExists(lpStateData->lpszWinBOMPath, INI_SEC_WBOM_SETTINGS, INI_KEY_WBOM_AUTOLOGON, INI_VAL_WBOM_YES) );
  56. }