Home » MSI (Windows Installer) » Useful Scripts for Custom Actions » Clean Up the Windows Start Menu

Clean Up the Windows Start Menu

Posted on by

Sometimes after an install or an uninstall we want to clean up the start menu – usually this involves removing shortcuts to uninstall the application, shortcuts that link to help files and/or shortcuts that attempt to install additional components.  This tidy script (tested on Windows 7) can be used to populate file(s) and folder(s) names that require deleting.

Option Explicit

dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject") 
dim objShell : Set objShell = CreateObject("WScript.Shell") 

dim strProgramsPath : strProgramsPath = objShell.ExpandEnvironmentStrings("%AllUsersProfile%") & "\Microsoft\Windows\Start Menu\Programs"

'delete an array of files (shortcuts) from the start menu
dim arrFilesToDelete : arrFilesToDelete = Array( _
	strProgramsPath & "\Folder1\Link1.lnk", _
	strProgramsPath & "\Folder1\Link2.lnk", _
	strProgramsPath & "\Folder2\Link3.lnk", _
	strProgramsPath & "\Folder2\Link4.lnk" _
	)

dim strFile
For Each strFile In arrFilesToDelete
	If objFSO.FileExists(strFile) Then objFSO.DeleteFile strFile, True
Next

'delete an array of folders from the Start Menu
dim arrFoldersToDelete : arrFoldersToDelete = Array( _
	strProgramsPath & "\Folder1", _
	strProgramsPath & "\Folder2" _
	)

dim strFolder
For Each strFolder In arrFoldersToDelete
	If objFSO.FolderExists(strFolder) Then objFSO.DeleteFolder strFolder, True
Next

Set objFSO = Nothing
Set objShell = Nothing

 

Comments have now been disabled. If you have a question to ask about this post please ask the community!