Add GetPackageFullName helper

This commit is contained in:
ge0rdi
2020-09-20 08:20:34 +02:00
parent 728f982310
commit 95f3a4b09a
2 changed files with 21 additions and 14 deletions

View File

@@ -301,21 +301,12 @@ bool CanUninstallMetroApp( const wchar_t *appid )
// Uninstalls the app with the given id
void UninstallMetroApp( const wchar_t *appid )
{
CComPtr<IShellItem> pAppItem;
if (SUCCEEDED(SHCreateItemInKnownFolder(FOLDERID_AppsFolder2,0,appid,IID_IShellItem,(void**)&pAppItem)))
auto packageName = GetPackageFullName(appid);
if (!packageName.IsEmpty())
{
CComPtr<IPropertyStore> pStore;
pAppItem->BindToHandler(NULL,BHID_PropertyStore,IID_IPropertyStore,(void**)&pStore);
if (pStore)
{
CString packageName=GetPropertyStoreString(pStore,PKEY_MetroPackageName);
if (!packageName.IsEmpty())
{
wchar_t command[1024];
Sprintf(command,_countof(command),L"Remove-AppxPackage %s",packageName);
ShellExecute(NULL,L"open",L"powershell.exe",command,NULL,SW_HIDE);
}
}
wchar_t command[1024];
Sprintf(command, _countof(command), L"Remove-AppxPackage %s", packageName);
ShellExecute(NULL, L"open", L"powershell.exe", command, NULL, SW_HIDE);
}
}
@@ -381,3 +372,16 @@ bool IsEdgeDefaultBrowser( void )
}
return false;
}
CString GetPackageFullName(const wchar_t* appId)
{
CComPtr<IShellItem> item;
if (SUCCEEDED(SHCreateItemInKnownFolder(FOLDERID_AppsFolder, 0, appId, IID_PPV_ARGS(&item))))
{
CComPtr<IPropertyStore> store;
if (SUCCEEDED(item->BindToHandler(nullptr, BHID_PropertyStore, IID_PPV_ARGS(&store))))
return GetPropertyStoreString(store, PKEY_MetroPackageName);
}
return {};
}

View File

@@ -53,3 +53,6 @@ CComPtr<IContextMenu> GetMetroPinMenu( const wchar_t *appid );
// Determines if Edge is the default browser
bool IsEdgeDefaultBrowser( void );
// Returns full package name for given App ID
CString GetPackageFullName(const wchar_t* appId);