Skip to main content

How to Remove a Program from the Start Menu in Batch Script

When uninstalling software or cleaning up a hastily deployed set of tools, removing lingering shortcut icons from the Windows Start Menu is a necessary step. Leaving "dead" shortcuts behind creates a poor user experience. In this guide, we will explore how to gracefully remove programs, shortcuts, and folders from the Start Menu using Batch Script.

This technique is essential for system administrators writing custom uninstaller scripts or IT professionals maintaining clean, standardized desktop environments.

Where Start Menu Shortcuts Reside

The Start Menu consolidates shortcuts from two primary locations:

  1. Current User: Contains shortcuts installed only for the active user.
    • Path: %APPDATA%\Microsoft\Windows\Start Menu\Programs
  2. All Users: Contains shortcuts installed system-wide for everyone. Requires administrative privileges to modify.
    • Path: %PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs

To thoroughly clean up a program, your script should ideally check both locations.

Method 1: Removing a Shortcut for the Current User

If you know the software was installed under the current user's profile, a simple del command targeting the .lnk file is sufficient.

@echo off
setlocal

:: Define the target shortcut name
set "shortcut_name=My Custom App.lnk"
set "start_menu=%APPDATA%\Microsoft\Windows\Start Menu\Programs"

echo Locating shortcut: "%shortcut_name%"...

:: Check if the file exists before attempting deletion
if exist "%start_menu%\%shortcut_name%" (
del /f /q "%start_menu%\%shortcut_name%"
echo [OK] Shortcut removed successfully from Current User Start Menu.
) else (
echo [INFO] Shortcut not found in Current User Profile.
)

pause

Explanation of the DEL Command

  • /f: Force deletion of read-only files.
  • /q: Quiet mode; do not ask for confirmation (essential for automated scripts).

Method 2: Removing a Shortcut for All Users (System-Wide)

Removing a shortcut installed for every user on the system requires your Batch script to be run as an Administrator.

@echo off
setlocal

:: Admin check before proceeding
net session >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Must run as Administrator to delete from All Users.
pause
exit /b 1
)

set "shortcut_name=Network Scanner.lnk"
set "all_users_sm=%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs"

echo Searching "All Users" Start Menu...

if exist "%all_users_sm%\%shortcut_name%" (
del /f /q "%all_users_sm%\%shortcut_name%"
echo [OK] Removed from All Users.
) else (
echo [INFO] Shortcut not found system-wide.
)

pause

Method 3: Removing an Entire Application Folder

Well-behaved applications group their shortcuts (e.g., the main app, uninstaller, help documentation) inside a dedicated subfolder within the Start Menu. Removing the entire folder is often cleaner than deleting individual .lnk files.

Use the rd (Remove Directory) command for this purpose.

@echo off
setlocal

set "app_folder=My Company IT Suite"

:: Check Current User
set "cu_folder=%APPDATA%\Microsoft\Windows\Start Menu\Programs\%app_folder%"
if exist "%cu_folder%" (
echo Found in Current User. Removing folder...
rd /s /q "%cu_folder%"
if exist "%cu_folder%" (
echo [ERROR] Failed to remove folder. Check permissions.
) else (
echo [OK] Folder deleted from Current User.
)
)

:: Check All Users (requires Administrator privileges)
set "au_folder=%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\%app_folder%"
if exist "%au_folder%" (
echo Found in All Users. Removing folder...
net session >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Administrator privileges required to remove All Users folder.
) else (
rd /s /q "%au_folder%"
if exist "%au_folder%" (
echo [ERROR] Failed to remove folder. Check permissions.
) else (
echo [OK] Folder deleted from All Users.
)
)
)

pause

Explanation of the RD Command

  • /s: Removes all directories and files in the specified directory in addition to the directory itself. This is required to delete a folder that is not empty.
  • /q: Quiet mode; suppresses the confirmation prompt.

The "Shotgun" Approach: Search and Destroy

In some scenarios, you might not know if the shortcut was installed per-user or system-wide, or you might be cleaning up a machine with multiple active profiles. A robust uninstaller script will attempt to remove the shortcut from both common locations automatically.

@echo off
setlocal enabledelayedexpansion

:: Check for Admin rights
net session >nul 2>&1
if !errorlevel! == 0 (
set "is_admin=true"
) else (
set "is_admin=false"
echo [WARNING] Running without Admin rights. System-wide cleanup will fail.
)

set "target=Legacy App.lnk"
set "cu_path=%APPDATA%\Microsoft\Windows\Start Menu\Programs\%target%"
set "au_path=%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\%target%"

echo Removing "%target%"...

:: Attempt Current User deletion
if exist "!cu_path!" (
del /f /q "!cu_path!"
echo [OK] Removed from Current User profile.
)

:: Attempt All Users deletion (requires Admin)
if exist "!au_path!" (
if "!is_admin!" == "true" (
del /f /q "!au_path!"
echo [OK] Removed system-wide (All Users^).
) else (
echo [ERROR] Found in All Users, but lack permissions to delete.
)
)

pause

Common Mistakes

The Wrong Way: Deleting the Folder Without the /s Switch

:: WRONG - The folder will not delete if it contains files
rd "%APPDATA%\Microsoft\Windows\Start Menu\Programs\My Suite"

Output Concern: If the folder contains shortcuts, the script will produce an error: The directory is not empty., and the folder will remain in the Start Menu.

The Correct Way: Always Use /s and /q

:: CORRECT - Deletes folder and all contents silently
rd /s /q "%APPDATA%\Microsoft\Windows\Start Menu\Programs\My Suite"

The Wrong Way: Using Hardcoded Drive Paths

:: WRONG - Profiles move based on OS installation drives
del "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\App.lnk"

Output Concern: While this works on 90% of machines, it will fail if Windows is installed on a different drive (e.g., D:\).

The Correct Way: Use Environment Variables

:: CORRECT - Always resolves to the OS drive automatically
del "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\App.lnk"

Best Practices

  1. Check both paths: Always attempt removal in both %APPDATA% and %PROGRAMDATA% to ensure a clean uninstall.
  2. Handle Admin requests gracefully: If attempting to delete from %PROGRAMDATA%, warn the user or auto-elevate the script using an admin-check routine if privileges are missing.
  3. Delete folders over files: When an entire suite folder was created during installation, remove the root folder via rd /s /q instead of deleting specific .lnk files inside it. The Start Menu dynamically removes empty folders, but it's cleaner to handle it explicitly.
  4. Use /f and /q: Suppress confirmation dialogs to keep scripts fully automated and capable of silent deployment or uninstallation via systems like Microsoft SCCM or Intune.

Conclusion

Removing programs from the Start Menu via Batch Script involves accurately targeting the .lnk files or application folders within the Current User and All Users Start Menu directories. By leveraging environment variables, correctly structuring del and rd flags, and gracefully handling administrative restrictions, you can programmatically ensure clean uninstalls and maintain an organized desktop infrastructure.