Programmatically get the windows store app details in windows machine

checkingrandom 206 Reputation points
2023-09-14T06:07:10.27+00:00

Hi was trying to get the windows store app details using PackageManager, but it list many result.

I was exactly looking to get the store app details which are listed in Add or Remove Program.

How windows classifies these store apps are needed to be shown in Add or Remove Program List.

How can we achieve this using c++, whether c++/WinRT can make this job quicker or is there any other Native API available.

Thanks in Advance

It will be much useful is there are any documentation or sample code snippet.

Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
5,099 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,636 questions
{count} votes

Accepted answer
  1. Castorix31 83,206 Reputation points
    2023-09-14T13:45:19.36+00:00

    With this test, it filters Store apps (C++/Win32) =>

    (as Admin ("requireAdministrator (/level='requireAdministrator')" in Manifest), I get 74 apps...)

    	PackageManager packageManager;
    	if (IsUserAnAdmin()) // #include <Shlobj.h>
    	{
    		int nCpt = 1;
    		for (const auto& package : packageManager.FindPackages())
    		{
    			try
    			{
    				auto nSignatureKind = package.SignatureKind();
    				auto hstrFamiliyName = package.Id().FamilyName();
    				if (nSignatureKind == PackageSignatureKind::Store && !package.IsFramework())
    				{				
    					auto pwsDisplayName = package.DisplayName().c_str();							
    					auto pwsFamiliyName = hstrFamiliyName.c_str();
    					WCHAR wsText[255] = L"";
    					wsprintf(wsText, L"Package n°%d\n", nCpt);
    					OutputDebugString(wsText);
    					wsprintf(wsText, L"\tDisplay Name : %s\n", pwsDisplayName);
    					OutputDebugString(wsText);
    					wsprintf(wsText, L"\tFamily Name : %s\n", pwsFamiliyName);
    					OutputDebugString(wsText);
    					nCpt++;
    				}
    			}
    			// Uncheck break on hresult_error in Debugger...
    			catch (winrt::hresult_error const& ex)
    			{							
    				std::wstring wsError = std::to_wstring(ex.code().value);
    				auto pwsMessage = ex.message().c_str();
    				WCHAR wsText[255] = L"";
    				wsprintf(wsText, L"Error : %s (%s)\n", pwsMessage, wsError.c_str());
    				OutputDebugString(wsText);
    			}			
    		}
    	}
    
    0 comments No comments

0 additional answers

Sort by: Most helpful