{"record":{"id":"63a7adff963d4c68","repo":"puppetlabs/puppet","slug":"failed-to-load-user-profile-user","errorCode":null,"errorMessage":"Failed to load user profile %{user}","messagePattern":"Failed to load user profile %(.+?)","errorType":"exception","errorClass":"Puppet::Util::Windows::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/windows/user.rb","lineNumber":133,"sourceCode":"  module_function :logon_user\n\n  def self.logon_user_by_logon_type(name, domain, password, logon_type, logon_provider, token)\n    LogonUserW(wide_string(name), wide_string(domain), password.nil? ? FFI::Pointer::NULL : wide_string(password), logon_type, logon_provider, token)\n  end\n\n  private_class_method :logon_user_by_logon_type\n\n  def load_profile(user, password)\n    logon_user(user, password) do |token|\n      FFI::MemoryPointer.from_string_to_wide_string(user) do |lpUserName|\n        pi = PROFILEINFO.new\n        pi[:dwSize] = PROFILEINFO.size\n        pi[:dwFlags] = 1 # PI_NOUI - prevents display of profile error msgs\n        pi[:lpUserName] = lpUserName\n\n        # Load the profile. Since it doesn't exist, it will be created\n        if LoadUserProfileW(token, pi.pointer) == FFI::WIN32_FALSE\n          raise Puppet::Util::Windows::Error, _(\"Failed to load user profile %{user}\") % { user: user.inspect }\n        end\n\n        Puppet.debug(\"Loaded profile for #{user}\")\n\n        if UnloadUserProfile(token, pi[:hProfile]) == FFI::WIN32_FALSE\n          raise Puppet::Util::Windows::Error, _(\"Failed to unload user profile %{user}\") % { user: user.inspect }\n        end\n      end\n    end\n  end\n  module_function :load_profile\n\n  def get_rights(name)\n    user_info = Puppet::Util::Windows::SID.name_to_principal(name.sub(/^\\.\\\\/, \"#{Puppet::Util::Windows::ADSI.computer_name}\\\\\"))\n    return \"\" unless user_info\n\n    rights = []\n    rights_pointer = FFI::MemoryPointer.new(:pointer)","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/windows/user.rb#L115-L151","documentation":"Raised by Puppet::Util::Windows::User.load_profile when LoadUserProfileW returns FALSE after a successful LogonUserW. The method logs on as the user (with PI_NOUI set to suppress profile error dialogs) to create/load the profile and then unload it. Puppet::Util::Windows::Error attaches the Win32 reason — typical codes are ERROR_ACCESS_DENIED (not elevated / profile store off-limits) and errors from a corrupt or locked ntuser.dat.","triggerScenarios":"Loading a profile while the process is not elevated; the user's registry hive (ntuser.dat) is locked by another process or corrupt; profile service (ProfSvc) issues; the profile path pointing to an unavailable location (roaming profile share down); disk full preventing profile creation.","commonSituations":"Puppet creating local users and immediately loading profiles in the same run on machines where the agent runs non-elevated; roaming profiles on an unreachable share; a previous run crashed leaving the hive loaded (temp profile accumulation); profile list in the registry referencing deleted directories.","solutions":["Run elevated — LoadUserProfileW typically requires administrator privileges for other users' profiles.","Check the Win32 code in the exception and the Application log (ProfSvc / User Profile Service events) for the specific failure.","If the hive is stale-locked, unload it (or reboot) and delete leftover temp profiles before retrying.","Verify the profile path exists or is creatable (roaming share reachable, quota/disk space available).","Re-run Puppet after fixing; profile creation is usually idempotent once the blocker is removed."],"exampleFix":"# before\nPuppet::Util::Windows::User.load_profile(user, password)\n\n# after - surface profile-service context on failure\nbegin\n  Puppet::Util::Windows::User.load_profile(user, password)\nrescue Puppet::Util::Windows::Error => e\n  Puppet.err(\"Profile load for #{user} failed (Win32 #{e.code}); check ProfSvc events in the Application log\")\n  raise\nend","handlingStrategy":"try-catch","validationCode":"# cheap pre-checks: user exists and profile service is running\nraise 'ProfSvc not running' unless `sc query ProfSvc` =~ /RUNNING/\nraise 'no such user' unless Puppet::Util::Windows::SID.name_to_principal(user)","typeGuard":null,"tryCatchPattern":"begin\n  Puppet::Util::Windows::User.load_profile(user, password)\nrescue Puppet::Util::Windows::Error => e\n  raise unless e.message.include?('Failed to load user profile')\n  raise 'load_profile requires an elevated process' if e.code == 5\n  raise \"profile issue (Win32 #{e.code}); check User Profile Service events\"\nend","preventionTips":["Always run profile operations elevated.","Keep the User Profile Service healthy; check Application log events 1511/1530 for profile errors.","Clean up stale temp profiles and unloaded hives before automation."],"tags":["windows","user-profile","win32","logon","puppet"],"backgroundTag":"user-profile-load-failed","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}