0

At some point I have set AppUserModel.RelaunchIconResource ID to 0 and now program doesn't have an icon in taskbar.

Breaking code:

IPropertyStore propStore = GetWindowPropertyStore(hwnd);
using (PROPVARIANT pv = new PROPVARIANT(0)
    propStore.SetValue(PROPERTYKEY.System.AppUserModel.RelaunchIconResource, pv);
Marshal.ReleaseComObject(propStore);

Icon is missing even if I don't set AppUserModel.ID when window is opened.

Icons is also missing if I use AppUserModel.ID that had icon deleted in the past and even if I try setting a new icon

using (PROPVARIANT pv = new PROPVARIANT(@"C:\path\prog.exe"))
    propStore.SetValue(PROPERTYKEY.System.AppUserModel.RelaunchIconResource, pv);

I have tried setting icon without specifying AppUserModel.ID

Icon is OK if I set the AppUserModel.ID to a random string, but not if I omit it or use one of old broken AppUserModel.ID.

How can I get the icon back for already broken AppUserModel.ID or if I don't set AppUserModel.ID at all?

I have tried searching registry for program's full path and also for the broken AppUserModel.ID.

Daniel
  • 1,064
  • 2
  • 13
  • 30
  • Have you tried to set the value to VT_EMPTY? This is how one removes a property from a property store (https://learn.microsoft.com/en-us/windows/win32/api/propsys/nf-propsys-ipropertystore-setvalue#remarks) – Simon Mourier Jan 13 '23 at 08:13
  • @SimonMourier VT_EMPTY in all examples I have found is just enum value that equals to 0, which is how I originally broke the icons – Daniel Jan 13 '23 at 17:22
  • Yes, I know VT_EMPTY value is 0, but it's the official way to remove a property from a property store, and no, it's *not* the same as a PROPVARIANT containing an integer such a 0 (like VT_I4, VT_UI4, VT_I2, VT_UI2, etc.). I don't know how you define PROPVARIANT(0), but I guess it's an integer PROPVARIANT, not the empty PROPVARIANT. – Simon Mourier Jan 13 '23 at 17:57
  • @SimonMourier it was actually already set to `using (PROPVARIANT pv = new PROPVARIANT((ushort)System.Runtime.InteropServices.VarEnum.VT_EMPTY))` – Daniel Jan 22 '23 at 01:25
  • I've tested a window property store and a property is indeed deleted when we call SetValue with an empty PROPVARIANT. How is this PROPVARIANT class defined? Where is the (C# I believe) source so we can check what it does exactly? – Simon Mourier Jan 22 '23 at 16:02

0 Answers0