1

Most of games I install are GOG versions and the installers generate loads of unnecessary files, all have uninstallers, and if I want to uninstall, I will just delete the installation folder. I use this PowerShell command to delete these useless files, which works:

# I have confirmed deleting these files doesn't affect the functions of the games

function Remove-GOG ($game) {
  Get-ChildItem -path $game -file | Where-Object {$_.fullname -match "gog.ico|goggame|support.ico|webcache|gameuxinstallhelper.dll|unins\d{3}|launch.+\.lnk|eula.txt"} | remove-item
}

However, whenever I launch such a game using the executable directly, its icon in the taskbar is a blank one, the generic icon for shortcuts whose icons are deleted.

  • The executable itself contains icons, and I didn't launch the game using a shortcut.
  • The executable isn't pinned to the taskbar, and the icons aren't present within:
    %APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar
    
  • The shortcut is the same as launch {game_name}.lnk and it uses a goggame-{game_id}\.(ico|dll) icon file, which is deleted using the above PowerShell function

How can I programmatically delete the ghost shortcuts in the Registry and restore the original icons to the Taskbar shortcuts?


To resolve and manually change the icon through the slow GUI (being greeted by a file not found message first) after launching the game, I have to switch to the Desktop via:

  • Alt+Tab → Right-click the Taskbar shortcut → PropertiesChange Icon...

I believe the shortcut must be associated with the executable in the Registry, making the Taskbar icons use the deleted .ico files, and whenever I run the game directly, the shortcut overwrites the Taskbar icon of the executable despite the shortcut file being deleted.

  • After tediously searching Google, I have found the most relevant key to be, but have no idea if it is the key:
    HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\UFH\SHC
    
  • I want the Taskbar icon to use an icon found inside the executable itself when given the absolute path of the executable.
2
  • Shortcuts link to an external file in order to get the icon. You deleted the icon, so that's why it doesn't show. An icon can be embedded inside an executable, or it can be stand-alone. No icon file to open, blank icon. Its that simple.
    – LPChip
    Commented Feb 14 at 8:02
  • @LPChip You clearly misunderstood my question. I have stated very clearly that I started the games using the executable directly and I have deleted the .lnk shortcut, and somehow the taskbar icon uses the deleted .lnk file. Commented Feb 14 at 8:09

1 Answer 1

1

The problem is simple, when GOG installers install the games, they create shortcuts in the game directory and shortcuts in the start menu. All these shortcuts use the icon files found in the installation directory, which I stated before are deleted.

Each time a game is installed a key is created, containing the following, in:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\UFH\SHC]
"224"=hex(7):43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,44,00,61,00,74,00,61,00,5c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,00,73,00,5c,00,53,00,74,00,61,00,72,00,74,00,20,00,4d,00,65,00,6e,00,75,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,73,00,5c,00,41,00,76,00,61,00,64,00,6f,00,6e,00,20,00,32,00,20,00,2d,00,20,00,54,00,68,00,65,00,20,00,43,00,6f,00,72,00,72,00,75,00,70,00,74,00,69,00,6f,00,6e,00,20,00,5b,00,47,00,4f,00,47,00,2e,00,63,00,6f,00,6d,00,5d,00,5c,00,41,00,76,00,61,00,64,00,6f,00,6e,00,20,00,32,00,20,00,2d,00,20,00,54,00,68,00,65,00,20,00,43,00,6f,00,72,00,72,00,75,00,70,00,74,00,69,00,6f,00,6e,00,2e,00,6c,00,6e,00,6b,00,00,00,44,00,3a,00,5c,00,47,00,61,00,6d,00,65,00,73,00,5c,00,41,00,76,00,61,00,64,00,6f,00,6e,00,20,00,32,00,5c,00,41,00,76,00,61,00,64,00,6f,00,6e,00,20,00,32,00,2e,00,65,00,78,00,65,00,00,00,00,00,00,00
  • Decoding the data, we get something like the below; a REG_MULTI_SZ value with two lines, the first line being the shortcut file, and the second being the executable file it is associated with. For reasons I still don't fully understand, the shortcut file shows up within the taskbar whenever the executable is called, and it overwrites the executable's own icon because of the registry key:
    In [6]: bytearray(int(i, 16) for i in data.split(","))[::2].decode()
    Out[6]: 'C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Avadon 2 - The Corruption [GOG.com]\\Avadon 2 - The Corruption.lnk\x00D:\\Games\\Avadon 2\\Avadon 2.exe\x00\x00\x00'
    

I have verified this by modifying the taskbar icon's icon file, which modifies the shortcut in the start menu as well, and deleting the start menu folder restores the game executable's own icon.

This registry key can be queried, loop over all subkeys, find if the data's executable path matches the root game folder [D:/Games], and if it matches, delete this key and the associated start menu folder.

  • Python program I wrote to fix the problem:
    (I have never used winreg before and could write it in PowerShell, but that isn't fun, as I don't learn new things that way; I wrote it in Python, rigorously tested it, and it works perfectly)
    import shutil
    import winreg
    from pathlib import Path
    
    HKCU = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)
    UFH_SHC = winreg.OpenKey(
      HKCU, r"SOFTWARE\Microsoft\Windows\CurrentVersion\UFH\SHC", 0, winreg.KEY_ALL_ACCESS
    )
    
    def delete_GOG_shortcuts() -> None:
      num_values = winreg.QueryInfoKey(UFH_SHC)[1]
      names = []
      for i in range(num_values):
        name, data, _ = winreg.EnumValue(UFH_SHC, i)
        if "D:\\Games" in data[1]:
          folder = Path(data[0]).parent
          assert folder.name != "Programs"
          shutil.rmtree(folder, ignore_errors=True)
          names.append(name)
    
        for name in names:
          winreg.DeleteValue(UFH_SHC, name)
    

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .