Author Topic: Windows Codeblocks uninstall - Associations left over after uninstall  (Read 9399 times)

Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
On Windows when you uninstall Code::Blocks via the Windows uninstall process there are file associations left in the registry due to the code in the src\associations.cpp (Associations::DoSetAssociation function)  that are not removed on an uninstall... This is not very good IMHO.

You can use the following process to see the registry entries that have NOT been removed, assuming you have ccleaner (ccleaner slim is my preferred version)
1) Run ccleaner and clean the registry until no more registry entries can be cleaned.
2) Uninstall Code::Blocks
3) Rename/backup the Code::Blocks APPDATA directory (%APPDATA%\CodeBlocks)
4) Delete the Code::Blocks APPDATA directory (rmdir /q /s %APPDATA%\CodeBlocks)
5) Install Code::Blocks "codeblocks-20.03-setup.exe"
6) Run Code::Blocks and associate C/C++ to C::B
7) Exit Code::Blocks
5) Uninstall Code::Blocks
6) Run ccleaner and scan for registry entry issues. You should see a bunch of entries left over from C::B:

Should the NSIS script detect these registry entries and remove them or is there a better way of doing this?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Should the NSIS script detect these registry entries and remove them or is there a better way of doing this?
Windows is multiuser system. How are we supposed to do this in this environment?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
Quote
Windows is multiuser system. How are we supposed to do this in this environment?

If I knew this then I would not have asked.

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
If the installer establishes the associations, instead of Code::Blocks itself (or maybe in addition to), then an uninstall will remove and tidy up the associations.

Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
The NSIS script below removes some HKCU\SOFTWARE\Classes sub entries, but not the entries listed below,

Not Removed Associations:
   HKCU\SOFTWARE\Classes\.cbp
   HKCU\SOFTWARE\Classes\.cc
   HKCU\SOFTWARE\Classes\.tcc
   HKCU\SOFTWARE\Classes\.workspace
   HKCU\SOFTWARE\Classes\CodeBlocks.cpp
   HKCU\SOFTWARE\Classes\CodeBlocks.hpp
   HKCU\SOFTWARE\Classes\CodeBlocks.tpp

NSIS Script snippet that includes NSIS special build logging:
Code
    # Start Unregister CodeBlocks associated files - see FileAssocation.cpp
    # or check out the registry "Computer\HKEY_CURRENT_USER\SOFTWARE\Classes\CodeBlocks.*" entries.
   
    ${If} ${RunningX64}
        LogText "SetRegView 64"
        SetRegView 64
        StrCpy $0 0 ; Registry key index
        ; Length of "CodeBlocks" = 10
        enumunkey64:
            EnumRegKey $1 HKCU "SOFTWARE\Classes" $0
            ;LogText "Read HKCU\SOFTWARE\Classes\$1"
            IntOp $0 $0 + 1
            StrCmp $1 "" done64
            StrCpy $2 $1 10  0
            ; LogText "Read 0 = $0 , 1 = $1 , 2 = $2"
            StrCmp $2 "CodeBlocks" 0 enumunkey64
            StrLen $3 $1
            IntOp $3 $3 - 10    ; Includes .
            StrCpy $4 $1 $3 10  ; Includes .
            LogText "L2755 1 = $1 , 2 = $2 , 3 = $3 , 4 = $4"
            StrCmp $4 "" enumunkey64
            ReadRegStr $5 HKCU "SOFTWARE\Classes\$4" ""
            LogText "L2758 1 = $1 , 2 = $2 , 5 = $5"
            StrCmp $5 $1 0 DelCodeBlocksEntry64   ; If no file extension classes found then goto DelCodeBlocksEntry
            StrCmp $5 $2 0 DelCodeBlocksEntry64   ; If file extension classes is not for codeblocks entry goto DelCodeBlocksEntry
            LogText "TBA L2761 Found : 'SOFTWARE\Classes\$1'"
            LogText "ReadRegStr 'SOFTWARE\Classes\$4' returned $5"

            LogText "DeleteRegValue HKCU 'SOFTWARE\Classes\$4' ''"
            DeleteRegValue HKCU "SOFTWARE\Classes\$4" ""    ; Delete default as it is codeblocks
            LogText "DeleteRegKey /IfEmpty HKCU 'SOFTWARE\Classes\$4'"
            DeleteRegKey /IfEmpty HKCU "SOFTWARE\Classes\$4"
        DelCodeBlocksEntry64:
            DeleteRegKey HKCU "SOFTWARE\Classes\$1"
            Goto enumunkey64

        done64:   
        # Finish Unregister CodeBlocks associated files - see FileAssocation.cpp
        SetRegView 32
        LogText "SetRegView 32"
    ${EndIf}
       
    StrCpy $0 0 ; Registry key index
    ; Length of "CodeBlocks" = 10
    enumunkey:
        EnumRegKey $1 HKCU "SOFTWARE\Classes" $0
        ;LogText "Read HKCU\SOFTWARE\Classes\$1"
        IntOp $0 $0 + 1
        StrCmp $1 "" done
        StrCpy $2 $1 10  0
        ;LogText "Read 0 = $0 , 1 = $1 , 2 = $2"
        StrCmp $2 "CodeBlocks" 0 enumunkey
        StrLen $3 $1
        IntOp $3 $3 - 10    ; Includes .
        StrCpy $4 $1 $3 10  ; Includes .
        LogText "L2791 1 = $1 , 2 = $2 , 3 = $3 , 4 = $4"
        StrCmp $4 "" enumunkey
        ReadRegStr $5 HKCU "SOFTWARE\Classes\$4" ""
        LogText "L2794 1 = $1 , 2 = $2 , 5 = $5"
        StrCmp $5 $1 0 DelCodeBlocksEntry   ; If no file extension classes found then goto DelCodeBlocksEntry
        StrCmp $5 $2 0 DelCodeBlocksEntry   ; If file extension classes is not for codeblocks entry goto DelCodeBlocksEntry
        LogText "TBA L2797 Found : 'SOFTWARE\Classes\$1'"
        LogText "ReadRegStr 'SOFTWARE\Classes\$4' returned $5"

        LogText "DeleteRegValue HKCU 'SOFTWARE\Classes\$4' ''"
        DeleteRegValue HKCU "SOFTWARE\Classes\$4" ""    ; Delete default as it is codeblocks
        LogText "DeleteRegKey HKCU 'SOFTWARE\Classes\$4'"
        DeleteRegKey HKCU "SOFTWARE\Classes\$4"
    DelCodeBlocksEntry:
        DeleteRegKey HKCU "SOFTWARE\Classes\$1"
        Goto enumunkey


I have used the MS Process Monitor to see if there is any differences between the HKCU\SOFTWARE\Classes\CodeBlocks.tpp and HKCU\SOFTWARE\Classes\CodeBlocks.cbp access when running Code::Block for the first time when I associate CB with the C/C++ files and I could not see any differences, but I must have missed something as the CodeBlocks.cbp  is removed and the CodeBlocks.tpp is not....


Offline Krice

  • Almost regular
  • **
  • Posts: 150
Is this a big problem? I think some programs do this and Windows also has now user directories (etc.) where programs leave their files, which I think is annoying.

Offline sodev

  • Regular
  • ***
  • Posts: 497
The problem is, the installer usually runs with root rights, so the U of HKCU is root. But IIRC Codeblocks sets these associations as the user it runs under, which usually is not root, so its U is another one. Even worse, it could have more than one value for U. This could only be avoided if Codeblocks sets these associations under HKLM, but for this it needs to elevate itself to root. This also has the effect that these associations are now system wide instead of user only.

If the installer establishes the associations, instead of Code::Blocks itself (or maybe in addition to), then an uninstall will remove and tidy up the associations.

Not by itself, you have to add code to remove these associations yourself 8). Still, the same issues apply like mentioned above.

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
I have mainly some experience using InnoSetup, and then I believe this is not a problem (I have done similar with InnoSetup in the past).  "The uninstall info root key will always be HKEY_CURRENT_USER, and the "common" forms of the Shell Folder constants are mapped to the "user" forms, even if administrative privileges are available"

Probably these things are features of the installer being used. Probably NSIS is different, I'll leave it there.

Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
@sodev The keys listed that I have a problem with are added by the CB exe and as such are in the HKCU.

@cacb I have a "working" inno setup. It does a full install only and it is allot easier to implement the registry key removal code and after removed CCleaner does not find any registry issues (there are still fragments of CB in other registry entries that I need to check out). BTW I think I need to find a better registry checker program as searching the registry via regedit is slooowwwww.

The next step for me is to check the NSIS script registry removed code works the same way as the ISS pascal registry removal code and update it if there is any discrepancies.

Offline sodev

  • Regular
  • ***
  • Posts: 497
@sodev The keys listed that I have a problem with are added by the CB exe and as such are in the HKCU.
And this is the problem, as regular user you can only access YOUR HKCU, but not the HKCU of OTHER users. For this you need to be root, enumerate all user accounts and check their HKCU. At least for NSIS this is not (easily) possible.

Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
Re: Windows Codeblocks uninstall - Associations left over after uninstall
« Reply #10 on: July 28, 2021, 09:49:07 am »
This is not THE problem I am having as the NSIS CB installer does NOT add any file association keys. The CB exe adds the associations and if I select C/C++ it adds 12, but the NSIS uninstall code removed some of them, but not all as the "EnumRegKey" does not enumerate through all of the keys. It does not matter if I run the CB exe from the installer of after the installer has closed the keys are either way not removed. I used the NSIS 3.07 special build to log info and the keys did not appear in the output for the keys that were not deleted. I have modified the code to loop through the HKCU64 hive and then the HKCU32 hive (these were  added in NSIS 3.02 released on 23-July-2017)

My latest NSIS script is available from the following URL:
https://github.com/acotty/codeblocks_sf/blob/AC-WindowsInstaller/windows_installer/Installer_NSIS_x64.nsi

The registry removal code is currently between lines 2769 and 2826. This may change if I find any more issues in my testing, but it is looking complete apart from this one issue.