Hi @WST Developer ,
1. Checking whether a profile exists
There's no documented API that just checks whether a profile exists without changing anything. The documented approach is to call CreateAppContainerProfile and check the result. If it returns HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS), get the SID from the name, as shown in Launch an AppContainer.
DeriveAppContainerSidFromAppContainerName only documents S_OK and E_INVALIDARG, with no "profile not found" case, so getting S_OK doesn't confirm the profile exists.
You can use NetworkIsolationEnumAppContainers as extra evidence by filtering on your user SID and AppContainer SID. A match is a good sign, but no match doesn't prove the profile is missing. Remember to free the result with NetworkIsolationFreeAppContainers.
The HKCU mapping key isn't documented, so I wouldn't rely on it.
2. GetAppContainerFolderPath returning 0x80070002
ERROR_FILE_NOT_FOUND isn't documented for GetAppContainerFolderPath. Since you haven't called CreateAppContainerProfile for this name yet, a likely reason is that the profile simply doesn't exist, though the docs don't confirm this. Please also check whether the calling thread was impersonating, because that changes which user context the API uses.
A quick way to confirm:
- Create a test profile.
- Convert the returned SID with ConvertSidToStringSidW.
- Call GetAppContainerFolderPath with that string. If it works, that supports the missing-profile explanation.
- Delete the test profile afterwards.
3. Safe creation and rollback
Only treat the profile as yours when CreateAppContainerProfile returns S_OK. If it returns ERROR_ALREADY_EXISTS or any other error, don't mark it as owned and don't delete it during rollback. After S_OK, you can compare the returned SID with the derived SID and call GetAppContainerFolderPath as a check, but there's no documented API that lists every resource the profile creates. If these checks fail, roll back the profile as described below.
For cleanup, follow the DeleteAppContainerProfile docs: make sure your launched processes have exited and your handles are closed, call it from outside the container under the same user, and retry if it fails. There's no documented way to check whether other processes are using the profile, so you'll need to track the processes your own app launched.
If MSIX is an option, Windows manages the profile for you when the package is registered and unregistered. See AppContainer for legacy apps.
If you found this helpful, you can refer to this guidance to confirm it and help others with similar questions.
Thank you.