Jump to content
Sign in to follow this  
Skitty

Working with "Add or Remove Programs" Control Panel Applet

Recommended Posts

Skitty

I don't know how exactly to explain this, but I was making some functions to assist me in installing a script and having it registered in the "Add or Remove Programs" control panel applet, problem is I don't exactly know how to un-register it after a user decides to click "Remove" in its control panel entry.

The program executes correctly, removing all files and folders that it made but I am confused as to how to tell the "Add or Remove Programs" control panel applet that the uninstaller executed correctly so as to have it remove the entry without the user having to click it again and making the applet come up with the message that the installation is broken and if they would like to remove the entry.

I was reading this MSDN entry but I can't seem to find anything related to my problem.

I thought that just deleting the registry keys used to register the software uninstaller would do the trick but apparently not.

This is the test key I was using.

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\Test Application

And deleting it doesn't unregister the uninstaller when it's finished, how should I do this?

Edited by THAT1ANONYMOUSEDUDE

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites
sleepydvdr

Perhaps this reg key:

HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstall


#include <ByteMe.au3>

Share this post


Link to post
Share on other sites
Skitty

Perhaps this reg key:

HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstall

Thanks for teh effort but it's the same deal, only difference is if I use that one I'll install the application and register it for every user on a system in relation to using HKCU which will only install it for the current user.

My problem is I don't know how to communicate with the "Add or Remove Programs" control panel applet so as to let it know my application uninstaller executed successfully so it can remove my software entry in its software list.


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites
JLogan3o13

sleepydvdr is correct, you want the uninstall key under HKLM, rather than HKCU. I would further suggest, if you are going to do an install for your apps to deploy them to machines, that you give a repackaging tool a look. One free tool is Wix, which will bundle the app into an MSI for you, then on uninstall, you don't have to worry about leftovers :oops:


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
zorphnog

What entries to you have in your 'Test Application' key? I assume you are adding an UninstallString with the path to your uninstaller. Removing the registry key should remove it from the add/remove applet. Although, you may need to refresh (F5) to see it removed.

Share this post


Link to post
Share on other sites
sleepydvdr

I use Inno Setup to create installers. It's pretty easy to learn and makes your program look professional. Plus, it supports silent switches. Just another thing to consider.


#include <ByteMe.au3>

Share this post


Link to post
Share on other sites
JLogan3o13

Does Inno Setup create a compiled Setup.exe or an MSI? I'll have to check it out sometime. I use Admin Studio, but it is quite pricey if you're not packaging all the time.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Skitty

sleepydvdr is correct, you want the uninstall key under HKLM, rather than HKCU. I would further suggest, if you are going to do an install for your apps to deploy them to machines, that you give a repackaging tool a look. One free tool is Wix, which will bundle the app into an MSI for you, then on uninstall, you don't have to worry about leftovers :oops:

Well then, I don't really know, I got the idea that installing it under HKLM and HKCU was no different aside from the installation entry in the control panel applet I was talking about not showing up if it's a different user, I got this impression after looking at the method google uses to register their applications for a particular user, they seem to favor using the HKCU base to register their browser and browser uninstaller instead of registering it for every user on a machine.

What entries to you have in your 'Test Application' key? I assume you are adding an UninstallString with the path to your uninstaller. Removing the registry key should remove it from the add/remove applet. Although, you may need to refresh (F5) to see it removed.

Windows Registry Editor Version 5.00
[HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionUninstallTast App]
"InstallLocation"="C:Program FilesTast App"
"DisplayName"="Tast App"
"DisplayIcon"="C:Documents and SettingsTESTDesktopInstallerUninstaller test.exe,0"
"Publisher"="Me"
"HelpLink"="http://www.randomaddress.com"
"DisplayVersion"="3.3.8.1"
"Version"="3.3.8.1"
"NoModify"=dword:00000001
"NoRepair"=dword:00000001
"InstallDate"="20120302"
"ID"=dword:00000001
"UninstallString"="C:Program FilesTast AppUninstaller test.exe --uninstall"

Those are the values used. And removing them doesn't refresh the control panel applet, I want the CPL applet to refresh automatically once the uninstallation has completed successfully like when you remove chrome or any other mainstream application.

I use Inno Setup to create installers. It's pretty easy to learn and makes your program look professional. Plus, it supports silent switches. Just another thing to consider.

Thanks, but the point is I want to create the software only using autoit and no 3rd party utilities.

Edit: Forgot I had some vulgar language in the registery...

Edited by THAT1ANONYMOUSEDUDE

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites
zorphnog

I've tested removing the registry key and it removes the application from my Add/Remove applet. Here are a few things that would help:

1. What OS version are you using?

2. Do you simply have a typo (I noticed your .reg file had 'Tast App' instead of Test)?

3. Is your Uninstaller test.exe the actual script that is performing the uninstall procedures or does it call another file and exit execution?

No. 3 is important because the Add/Remove applet is simply waiting for the UninstallString process to end before it updates it's display. If you are calling a separate executable from Uninstall test.exe and not blocking (i.e. Run() instead of RunWait()) then your process might finish before you've deleted the registry entries. Finally, if all else fails, post your script so we can actually see what is executing otherwise most of this is just a shot in the dark.

Share this post


Link to post
Share on other sites
Skitty

I've tested removing the registry key and it removes the application from my Add/Remove applet. Here are a few things that would help:

1. What OS version are you using?

2. Do you simply have a typo (I noticed your .reg file had 'Tast App' instead of Test)?

3. Is your Uninstaller test.exe the actual script that is performing the uninstall procedures or does it call another file and exit execution?

No. 3 is important because the Add/Remove applet is simply waiting for the UninstallString process to end before it updates it's display. If you are calling a separate executable from Uninstall test.exe and not blocking (i.e. Run() instead of RunWait()) then your process might finish before you've deleted the registry entries. Finally, if all else fails, post your script so we can actually see what is executing otherwise most of this is just a shot in the dark.

Sorry for the late response, I decided that if I was to explain myself, doing it with a script would be my best bet.

I was busy adding a UDF header and comments to what I was doing so it could be a little easier to understand, the script is very simple and straight forward and I even added an example.

SI.au3

SI Example.au3


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites
zorphnog

Ok. I've got it working on my machine (Win7 32-bit/AutoIt 3.3.8.1). There were a few things I had to do to get it working:

1. Incorrect error handling of directory actions (DirCreate/DirRemove). These functions do not set @error, which is how you were checking.

2. UAC admin rights are required to create a directory in 'Program Files' (Found this out when the 'Tast App' directory was not being created).

3. You were not using any error checking on the RegDelete portion of your CheckUninstallRequest. As a result, you would not have known that the value you were trying to delete did not exist. Your original code was attempting to delete the 'Tast App' value under the uninstall key and not the 'Tast App' key itself.

Here are the changes I made to SI.au3:

Func _Install($DisplayName, $Publisher, $DisplayIcon, $SelfDelete = False, $InstallLocation = @ProgramFilesDir, $HKType = "HKCU", $DisplayVersion = Default, $HelpLink = False, $InstallFunc = False)
...
  If FileExists($InstallLocation) Then
    $CHECK = FileGetAttrib($InstallLocation)
    If Not StringInStr($CHECK,"D",2) Then Return SetError(3,0,False)
    $CHECK = $InstallLocation & "\" & $DisplayName
    If FileExists($CHECK) Then Return SetError(5,0,False)
    If Not DirCreate($CHECK) Then Return SetError(6,0,False)
  Else
    $CHECK = $InstallLocation & "\" & $DisplayName
    If Not DirCreate($CHECK) Then Return SetError(6,0,False)
  EndIf
...
EndFunc

and

#Region - Application Removal -

If FileGetShortName(@ScriptDir) <> FileGetShortName(@TempDir) Then; move a copy of this file to the temp directory so we can uninstall properly from there.
  Local $TmpFile = @TempDir & "\SetUp.exe"
  If FileExists($TmpFile) Then
    For $I = 0 To 99999999
      $TmpFile = @TempDir & "\SetUp(" & $I & ").exe"
      If Not FileExists($TmpFile) Then ExitLoop
    Next
    FileCopy(@ScriptFullPath,$TmpFile)
  EndIf
  FileCopy(@ScriptFullPath,$TmpFile)
  If Not ProcessExists(Run(FileGetShortName($TmpFile) & " --uninstall",@WorkingDir)) Then Return SetError(1,0,False)
  Exit
Else; we are already in the temp directory, commence operation to remove everything possible.
  If Not $HKType Then $HKType = "HKCU"
  $HKType = _CheckBaseKey($HKType)
  If $HKType = @error Then Return SetError(2,0,False)
  Local $Key = $HKType & "\Software\Microsoft\Windows\CurrentVersion\Uninstall\" & $DisplayName
  Local $Directory = RegRead($Key,"InstallLocation")
  If $Directory = @error Then SetError(3,0,False)
  If Not DirRemove($Directory,1) Then
    CloseExecMods($Directory); maybe we're locked because an application is running in our dir, lets locate exes and close them.
    If Not DirRemove($Directory,1) Then Return SetError(4,0,False)
  EndIf
  If RegDelete($Key) <> 1 Then Return SetError(5, 0, False)
  Return SetError(-1,0,True)
EndIf
#EndRegion - Application Removal -

And the changes to SI Example.au3:

#AutoIt3Wrapper_Compression=0
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
#include "SI.au3"

#cs
Run this once and it will install itselfe to program files under the folder name "Test App" and delete itselfe
Then go to the "Add Or Remove Programs" control panel applet and click remove, it will delete itselfe but
the control panel applet will remain and clicking it a second time will remove it after a warning is displayed
regarding the status of the installation.
#ce

Global $RetVal
If Not @Compiled Then Exit MsgBox(16,"Error!", "We need to be compiled, you cannot install a text file...")
If Not $CMDLINERAW Then
  $RetVal = _Install("Tast App", "AutoIt Community", 0, True)
  MsgBox(0,@error,$RetVal)
Else
  $RetVal = CheckUninstallRequest("Tast App")
  MsgBox(0,@error,$RetVal)
EndIf

Share this post


Link to post
Share on other sites
Skitty

Ok. I've got it working on my machine (Win7 32-bit/AutoIt 3.3.8.1). There were a few things I had to do to get it working:

1. Incorrect error handling of directory actions (DirCreate/DirRemove). These functions do not set @error, which is how you were checking.

2. UAC admin rights are required to create a directory in 'Program Files' (Found this out when the 'Tast App' directory was not being created).

3. You were not using any error checking on the RegDelete portion of your CheckUninstallRequest. As a result, you would not have known that the value you were trying to delete did not exist. Your original code was attempting to delete the 'Tast App' value under the uninstall key and not the 'Tast App' key itself.

Here are the changes I made to SI.au3:

Func _Install($DisplayName, $Publisher, $DisplayIcon, $SelfDelete = False, $InstallLocation = @ProgramFilesDir, $HKType = "HKCU", $DisplayVersion = Default, $HelpLink = False, $InstallFunc = False)
...
  If FileExists($InstallLocation) Then
    $CHECK = FileGetAttrib($InstallLocation)
    If Not StringInStr($CHECK,"D",2) Then Return SetError(3,0,False)
    $CHECK = $InstallLocation & "" & $DisplayName
    If FileExists($CHECK) Then Return SetError(5,0,False)
    If Not DirCreate($CHECK) Then Return SetError(6,0,False)
  Else
    $CHECK = $InstallLocation & "" & $DisplayName
    If Not DirCreate($CHECK) Then Return SetError(6,0,False)
  EndIf
...
EndFunc

and

#Region - Application Removal -

If FileGetShortName(@ScriptDir) <> FileGetShortName(@TempDir) Then; move a copy of this file to the temp directory so we can uninstall properly from there.
  Local $TmpFile = @TempDir & "SetUp.exe"
  If FileExists($TmpFile) Then
    For $I = 0 To 99999999
      $TmpFile = @TempDir & "SetUp(" & $I & ").exe"
      If Not FileExists($TmpFile) Then ExitLoop
    Next
    FileCopy(@ScriptFullPath,$TmpFile)
  EndIf
  FileCopy(@ScriptFullPath,$TmpFile)
  If Not ProcessExists(Run(FileGetShortName($TmpFile) & " --uninstall",@WorkingDir)) Then Return SetError(1,0,False)
  Exit
Else; we are already in the temp directory, commence operation to remove everything possible.
  If Not $HKType Then $HKType = "HKCU"
  $HKType = _CheckBaseKey($HKType)
  If $HKType = @error Then Return SetError(2,0,False)
  Local $Key = $HKType & "SoftwareMicrosoftWindowsCurrentVersionUninstall" & $DisplayName
  Local $Directory = RegRead($Key,"InstallLocation")
  If $Directory = @error Then SetError(3,0,False)
  If Not DirRemove($Directory,1) Then
    CloseExecMods($Directory); maybe we're locked because an application is running in our dir, lets locate exes and close them.
    If Not DirRemove($Directory,1) Then Return SetError(4,0,False)
  EndIf
  If RegDelete($Key) <> 1 Then Return SetError(5, 0, False)
  Return SetError(-1,0,True)
EndIf
#EndRegion - Application Removal -

And the changes to SI Example.au3:

#AutoIt3Wrapper_Compression=0
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
#include "SI.au3"

#cs
Run this once and it will install itselfe to program files under the folder name "Test App" and delete itselfe
Then go to the "Add Or Remove Programs" control panel applet and click remove, it will delete itselfe but
the control panel applet will remain and clicking it a second time will remove it after a warning is displayed
regarding the status of the installation.
#ce

Global $RetVal
If Not @Compiled Then Exit MsgBox(16,"Error!", "We need to be compiled, you cannot install a text file...")
If Not $CMDLINERAW Then
  $RetVal = _Install("Tast App", "AutoIt Community", 0, True)
  MsgBox(0,@error,$RetVal)
Else
  $RetVal = CheckUninstallRequest("Tast App")
  MsgBox(0,@error,$RetVal)
EndIf

Awesome! I was on XP and didn't take UAC into consideration at the time, but aside from that, these changes now invoke the entry removal of the application to pull through flawlessly, this is wonderful, it works perfectly.

I added you as an author to the UDF, maybe I'll post it later in example scripts after a little more testing.

Edited by THAT1ANONYMOUSEDUDE

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×