Supported recovery after LoadUserProfile owner exits without UnloadUserProfile

varlik manr 0 แต้มความนิยม
2026-10-07T07:54:28.4033333+00:00

Draft only — NOT SUBMITTED

Subject: Supported recovery after LoadUserProfile owner exits without UnloadUserProfile

On Windows, an application successfully called LoadUserProfile for a local non-administrator account. The application process terminated before calling UnloadUserProfile. The returned PROFILEINFO.hProfile and the application's retained user-token handle are no longer available. A later read-only check reports Win32_UserProfile.Loaded=true and the user's HKU and HKU_Classes hives present.

Does Microsoft provide a supported, non-destructive recovery procedure for this case?

Specifically:

  1. Can an appropriate profile ownership/reference be reacquired through a documented API without a new logon/profile load? If so, which API, provenance checks, handles and access rights are required?
  2. Does any documented lifecycle mechanism release an outstanding profile load after its owning process has exited? How should completion be verified?
  3. If no such route exists, please identify the supported recovery options and their prerequisites explicitly.

We need to preserve the profile files/settings and existing evidence. We are not authorized to substitute a newly opened registry handle, directly unload registry hives, alter privileges/security policy, restart/log off, or perform a new logon/profile load as an experiment. Please distinguish a documented supported procedure from an undocumented workaround.

OS edition/build and relevant sanitized event records can be provided after separately approved collection. No live machine state is being changed while awaiting clarification.

Windows สำหรับธุรกิจ | Windows Client สำหรับผู้เชี่ยวชาญด้านไอที | บริการไดเรกทอรี | การเข้าสู่ระบบและโปรไฟล์ของผู้ใช้
0 ความคิดเห็น ไม่มีข้อคิดเห็น

1 คำตอบ

เรียงลำดับตาม: มีประโยชน์มากที่สุด
  1. Daphne Huynh (WICLOUD CORPORATION) 2,700 แต้มความนิยม เจ้าหน้าที่ภายนอกของ Microsoft ผู้ควบคุม
    2026-10-19T10:11:11.7033333+00:00

    Welcome to Microsoft Q&A!

    Thank you for taking the time to provide such detailed information and for clearly describing the constraints around preserving the profile and the existing evidence.

    There is no documented API that allows a later process to reacquire or reconstruct the hProfile returned by an earlier successful LoadUserProfile call after that handle has been lost.

    1. Documented API contract

    LoadUserProfile requires a user token with TOKEN_QUERY, TOKEN_IMPERSONATE, and TOKEN_DUPLICATE access. The calling process must also have SE_RESTORE_NAME and SE_BACKUP_NAME privileges and, beginning with Windows XP SP2 and Windows Server 2003, must be an administrator or LocalSystem.

    After a successful call, PROFILEINFO.hProfile contains a registry-key handle opened with KEY_ALL_ACCESS to the root of the user's registry hive. Microsoft specifically states that the caller should not close this handle directly. Instead, it should be passed to UnloadUserProfile, which closes it.

    UnloadUserProfile requires:

    • A token for the user with TOKEN_IMPERSONATE and TOKEN_DUPLICATE access.
    • The hProfile value from the PROFILEINFO structure.
    • Administrative privileges.
    • All handles opened by the application under the user's registry hive to be closed before the unload operation.

    A successful call returns TRUE. Otherwise, GetLastError provides the extended error information.

    Microsoft's published user-profile API reference documents LoadUserProfile and UnloadUserProfile, but it does not document an API for attaching a new caller to an existing outstanding load by SID, profile path, or hive name.

    2. Why a new handle does not replace the original context

    Obtaining another token for the same user does not by itself reconstruct the lost hProfile.

    Likewise, opening HKEY_USERS\SID again gives the new process another registry-key handle. The documented UnloadUserProfile contract, however, identifies its hProfile parameter as the hProfile member of the PROFILEINFO structure associated with LoadUserProfile.

    DuplicateHandle can duplicate a registry-key handle between processes, but it requires a valid source handle in the context of the source process and PROCESS_DUP_HANDLE access to the relevant process handles. Therefore, it can be useful as part of a deliberately designed handle-transfer mechanism while the source handle remains available, but it does not provide a documented way to recover a handle that has already been lost when its owning process terminated.

    3. Does process termination automatically unload the profile?

    I would not rely on process termination alone as evidence that the original LoadUserProfile operation has been balanced.

    The LoadUserProfile documentation explicitly distinguishes closing a handle from unloading the profile: hProfile should be passed to UnloadUserProfile, rather than closed directly.

    Event ID 1530 should also not be interpreted by itself as evidence that an orphaned LoadUserProfile operation was successfully recovered. Microsoft documents this event as occurring when Windows automatically closes registry handles left open by an application while Windows is trying to close the user profile. The behavior is by design, and the application leaving the handle open should be investigated.

    4. Supported recovery position

    If the original hProfile and appropriate user-token context still exist, the documented cleanup path is to:

    • Close the registry handles opened by the application beneath the user's hive.
    • Call UnloadUserProfile with the appropriate user token and the hProfile returned by LoadUserProfile.
    • Verify that the call returns TRUE; if it fails, capture GetLastError.

    In the situation described here, however, the process has already terminated and the original hProfile and retained token are unavailable. The published user-profile API documentation does not provide an in-place API for reconstructing that lost LoadUserProfile context.

    Given your requirement to preserve the existing state and evidence, I would therefore leave the profile state unchanged rather than substitute a newly opened registry handle, perform another compensating LoadUserProfile/UnloadUserProfile sequence, or directly unload the hive.

    RegUnLoadKey, for example, is documented as a registry operation that unloads a key previously loaded with RegLoadKey, It is separate from the documented LoadUserProfile/UnloadUserProfile lifecycle.

    If an in-place resolution is required while restart/logoff and a new profile load are prohibited, the safest supported course is to preserve the current evidence and escalate the case for deeper Microsoft Support investigation rather than attempting to reconstruct or bypass undocumented User Profile Service state.

    5. Verification and evidence collection

    It is a recommendation starting profile load/unload troubleshooting with the Application log and then correlating relevant timestamps with theUser Profile Service > Operational log.

    If those logs are insufficient, Microsoft also documents more detailed diagnostic and ETL tracing for User Profile Service.

    For the documented UnloadUserProfile path, the primary programmatic success criterion is that UnloadUserProfile returns TRUE. Otherwise, GetLastError should be captured.

    Win32_UserProfile.Loaded, the presence of the SID hive, and User Profile Service events can be retained as observational evidence, but they should not be treated as a replacement for the documented UnloadUserProfile return value when that API path is available.

    6. Unsupported substitutions

    For this scenario, I would not present any of the following as a documented recovery procedure:

    • Passing a newly opened HKEY_USERS\SID handle as though it were the lost PROFILEINFO.hProfile.
    • Treating a newly obtained token for the same SID as ownership of the previous load.
    • Performing another LoadUserProfile/UnloadUserProfile pair and assuming that it balances the earlier operation.
    • Using RegUnLoadKey as a substitute for UnloadUserProfile. RegUnLoadKey is documented for registry hives loaded through RegLoadKey, not as the inverse of LoadUserProfile.
    • Changing ACLs, privileges, security policy, or profile data merely to force an unload.

    Conclusion:

    So, for the scenario described, there is no documented supported API for reacquiring the lost hProfile/load context after the process that called LoadUserProfile has terminated. The documented cleanup operation is UnloadUserProfile, using the appropriate user token and the hProfile associated with the corresponding LoadUserProfile operation.

    Since those inputs are no longer available and preserving the profile and evidence is a requirement, I would avoid substituting registry handles or using direct hive operations. Preserve the current state, collect the relevant User Profile Service and Application events, and escalate for Microsoft Support investigation if an in-place recovery is required without an approved restart, logoff, or new profile load.

    References: LoadUserProfileW function (userenv.h) - Win32 apps | Microsoft Learn

    UnloadUserProfile function (userenv.h) - Win32 apps | Microsoft Learn

    User Profiles Reference - Win32 apps | Microsoft Learn

    Event ID 1530 Is Logged in the Application Log - Windows Server | Microsoft Learn

    DuplicateHandle function (handleapi.h) - Win32 apps | Microsoft Learn

    PROFILEINFOW (profinfo.h) - Win32 apps | Microsoft Learn

    Win32_UserProfile class | Microsoft Learn

    RegUnLoadKeyW function (winreg.h) - Win32 apps | Microsoft Learn

    ProcessStartInfo.LoadUserProfile Property (System.Diagnostics) | Microsoft Learn

    Troubleshoot user profiles with events - Windows Server | Microsoft Learn

    User State Migration Tool (USMT) common issues - Windows Client | Microsoft Learn

    If you find it useful, please click Accept Answer.

    Thank you for choosing Microsoft Q&A.

    Note: This is the ไทย ‏ (th-th) forum. I kindly recommend posting your question in ไทย, as this will make it easier for other forum members and subject matter experts to engage with your inquiry. If you prefer to post in English, you may also consider using the English forum, where a larger English -speaking audience can review and respond to your question. Thank you for your understanding.

    คำตอบนี้มีประโยชน์หรือไม่

    0 ความคิดเห็น ไม่มีข้อคิดเห็น

คำตอบของคุณ

คำตอบสามารถทำเครื่องหมายว่า “ยอมรับ” โดยผู้เขียนคำถาม และ “แนะนำ” โดยผู้ดูแลระบบ ซึ่งจะช่วยให้ผู้ใช้ทราบว่าคำตอบนั้นแก้ไขปัญหาของผู้เขียนได้