MSI Deleting Folder/Directory/Leftover during Uninstall / Remove
If you need to delete leftovers from a program during uninstall / removal of an MSI Package, go ahead reading this post.
- Add this VBS Script to the Binary Table and call it DeleteFolderVbs (Column Name)
- Add the DeleteFolderVbs to the CustomAction Table, set the properties as follows:
- Action = DeleteFolderVbsCA
- Type = 6
- Source = DeleteFolderVbs
- Add the Action DeleteFolderVbsCA with Condition set to REMOVE=”ALL” to the InstallExecuteSequence with Sequence set to 6500
'==========================================================================
' NAME: DeleteDirectory.vbs
'
' AUTHOR: www.christiano.ch
' DATE : 20100811 (YYYYMMDD)
'
' COMMENT: removes directory
'
' USAGE / Syntax: DeleteDirectory.vbs
'
' CHANGE HISTORY:
' .........................................................................
' DATE of Change Who What
' -------------------------------------------------------------------------
' 20100811 Christian Muggli Created
'==========================================================================
Option Explicit
On Error Resume Next
' Constants
' msiMessageType
Public Const msiMessageTypeFatalExit = &H00000000 '// Premature termination, possibly fatal out of memory.
Public Const msiMessageTypeError = &H01000000 '// Formatted error message, [1] is message number in Error table.
Public Const msiMessageTypeWarning = &H02000000 '// Formatted warning message, [1] is message number in Error table.
Public Const msiMessageTypeUser = &H03000000 '// User request message, [1] is message number in Error table.
Public Const msiMessageTypeInfo = &H04000000 '// Informative message for log, not to be displayed.
Public Const msiMessageTypeFilesInUse = &H05000000 '// List of files in use that need to be replaced.
Public Const msiMessageTypeResolveSource = &H06000000 '// Request to determine a valid source location.
Public Const msiMessageTypeOutOfDiskSpace = &H07000000 '// Insufficient disk space message.
Public Const msiMessageTypeActionStart = &H08000000 '// Start of action,
' own
Public Const strLogFilePrefix = "Custom Error Logging Framework: "
WriteToMsiLog "Custom Script with Name: " & WScript.ScriptName & " started"
Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim lRet, strFolder
strFolder = Session.Property("TARGETDIR")
WriteToMsiLog "determined TARGETDIR.. Resolved to: " & strFolder
strFolder = MakePath(strFolder)
If strFolder <> "" Then
If oFSO.FolderExists(strFolder) Then
WriteToMsiLog "Path: " & strFolder & " exists - will try to delete it.."
lRet = oFSO.DeleteFolder(strFolder,True)
WriteToMsiLog "Deleting Path: " & strFolder & " seems to be successful."
End If
End If
Function WriteToMsiLog(strMessage)
Dim objMessage
Set objMessage = Session.Installer.CreateRecord(0)
objMessage.StringData(0) = strLogFilePrefix & strMessage
'If Session.Property("CUSTDEBUG") <> "" Then MsgBox "Message: " & strMessage
Session.Message msiMessageTypeInfo, objMessage
End Function
Function MakePath(strPath)
If Right(strPath, 1) = "\" Then
WriteToMsiLog "removing last backslash from path"
strPath = Left(strPath, Len(strPath)-1)
End If
MakePath = strPath
End Function
2 Responses to MSI Deleting Folder/Directory/Leftover during Uninstall / Remove
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
your solution give me an internal error 2721 msilog says:
————————————————————————————-
MSI (s) (74:EC) [12:45:12:514]: Doing action: DeleteFolderVbs
Action ended 12:45:12: PublishProduct. Return value 1.
MSI (s) (74:EC) [12:45:12:530]: Note: 1: 2235 2: 3: ExtendedType 4: SELECT `Action`,`Type`,`Source`,`Target`, NULL, `ExtendedType` FROM `CustomAction` WHERE `Action` = ‘DeleteFolderVbs’
MSI (s) (74:EC) [12:45:12:530]: Note: 1: 2721 2: DeleteFolderVbs
Action start 12:45:12: DeleteFolderVbs.
DEBUG: Error 2721: Custom action DeleteFolderVbs not found in Binary table stream
MSI (s) (74:EC) [12:45:12:546]: Product: SUPERAntiSpyware — Internal Error 2721. DeleteFolderVbs
Internal Error 2721. DeleteFolderVbs
———————————————————-
msi build whithout any errors
i hope you can help me , thanks
Johan Winter
Johan, the problem is, that you didnt set the properties of the CustomAction correctly. The must be:
Action = DeleteFolderVbsCA
Type = 6
Source = DeleteFolderVbs
Cheers, Christian