@@ -301,21 +301,12 @@ bool CanUninstallMetroApp( const wchar_t *appid )
301
301
// Uninstalls the app with the given id
302
302
void UninstallMetroApp ( const wchar_t *appid )
303
303
{
304
- CComPtr<IShellItem> pAppItem ;
305
- if (SUCCEEDED ( SHCreateItemInKnownFolder (FOLDERID_AppsFolder2, 0 ,appid,IID_IShellItem,( void **)&pAppItem) ))
304
+ auto packageName = GetPackageFullName (appid) ;
305
+ if (!packageName. IsEmpty ( ))
306
306
{
307
- CComPtr<IPropertyStore> pStore;
308
- pAppItem->BindToHandler (NULL ,BHID_PropertyStore,IID_IPropertyStore,(void **)&pStore);
309
- if (pStore)
310
- {
311
- CString packageName=GetPropertyStoreString (pStore,PKEY_MetroPackageName);
312
- if (!packageName.IsEmpty ())
313
- {
314
- wchar_t command[1024 ];
315
- Sprintf (command,_countof (command),L" Remove-AppxPackage %s" ,packageName);
316
- ShellExecute (NULL ,L" open" ,L" powershell.exe" ,command,NULL ,SW_HIDE);
317
- }
318
- }
307
+ wchar_t command[1024 ];
308
+ Sprintf (command, _countof (command), L" Remove-AppxPackage %s" , packageName);
309
+ ShellExecute (NULL , L" open" , L" powershell.exe" , command, NULL , SW_HIDE);
319
310
}
320
311
}
321
312
@@ -381,3 +372,16 @@ bool IsEdgeDefaultBrowser( void )
381
372
}
382
373
return false ;
383
374
}
375
+
376
+ CString GetPackageFullName (const wchar_t * appId)
377
+ {
378
+ CComPtr<IShellItem> item;
379
+ if (SUCCEEDED (SHCreateItemInKnownFolder (FOLDERID_AppsFolder, 0 , appId, IID_PPV_ARGS (&item))))
380
+ {
381
+ CComPtr<IPropertyStore> store;
382
+ if (SUCCEEDED (item->BindToHandler (nullptr , BHID_PropertyStore, IID_PPV_ARGS (&store))))
383
+ return GetPropertyStoreString (store, PKEY_MetroPackageName);
384
+ }
385
+
386
+ return {};
387
+ }
0 commit comments