Jump to content

Working with "Add or Remove Programs" Control Panel Applet


Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Moderators

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:

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Moderators

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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

This link is technically for NSIS, but I have used it before to register something manually. Still an ugly way to do it.

http://nsis.sourceforge.net/Add_uninstall_information_to_Add/Remove_Programs

Keep in mind I have found the first four or five items under "Optional Values" are not so optional.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...