Install a MSIX Sparse Package using ProvisionPackageForAllUsersAsync is not always worked

Glority 0 Reputation points
2025-08-05T06:38:21.2933333+00:00

Hi team,

In my code, I use PackageManager.StagePackageByUriAsync and PackageManager.ProvisionPackageForAllUsersAsync to install the package for all users in Win11 machine. The package is a MSIX Sparse Package used for the Modern Context Menu.

The problem is when I run the code in SYSTEM level, these two functions return success code every time. but the the package was not always installed successfully. The probability of success is about 50%. And another problem is even if the package installed successfully, sometimes I still can not see my application in the Modern Context Menu.

These problems are probabilistic, which lead to uncertain results every time I run this code in SYSTEM level. I always get a successful return from the function, but sometimes I can see my application in the Modern Context Menu, and sometimes I cannot.

Please help to check if is there any thing wrong in PackageManager API or in my code. I hope the result of the function is consistent with the actual package installation status and the Modern Context Menu can be registered for all users.


Here is part of the code:

PackageManager packageManager;
auto packagePath{ installDirectory / fs::path("SparsePackage64.msix") };
if (fs::exists(packagePath))
{
	Uri packageUri{ packagePath.native() };
	Uri appUri{ installDirectory.native() };
	StagePackageOptions options;
	options.ExternalLocationUri(appUri);
	auto operationStage{ packageManager.StagePackageByUriAsync(packageUri, options) };
	auto stageResult{ operationStage.get() };
	if (operationStage.Status() == AsyncStatus::Completed)
	{
		auto operationProvision{ packageManager.ProvisionPackageForAllUsersAsync(GetPackageFamilyName()) };
		auto provisionResult{ operationProvision.get() };
		if (operationProvision.Status() == AsyncStatus::Completed)
		{
			SHChangeNotify(SHCNE_ASSOCCHANGED, 0, nullptr, nullptr);
		}
		else
		{
			// handle error
		}
	}
	else
	{
		// handle error
	}
}

Tested Windows 11 is:

Windows 11 Enterprise 23H2 8/‎7/‎2024 22631.3958 Windows Feature Experience Pack 1000.22700.1026.0

Windows development | Windows App SDK
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.