How to delete all shortcuts pointing to an executable with GPO?

Alessandro Guizzetti 25 Reputation points
2023-03-15T20:20:10.8466667+00:00

Hello,

I want to delete all shortcuts that point to an executable with a GPO.

I don't know the name of the shortcut because they were created a long time ago manually from each computer, and now I need to replace them with new ones to other executables.

How can I do this?

Windows for business | Windows Client for IT Pros | Directory services | Active Directory
Windows for business | Windows Server | User experience | Other
Windows for business | Windows Client for IT Pros | User experience | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 44,751 Reputation points
    2023-03-16T15:08:59.3366667+00:00

    Hi,

    I'd be happy to help you out with your question. Sorry for the inconvenience caused.

    You can use a Group Policy Object (GPO) to delete all shortcuts that point to a specific executable by configuring a script that runs at startup. Here's how to do it:

    1. Create a new Group Policy Object in your domain and link it to the appropriate Organizational Unit.
    2. Edit the Group Policy Object and go to User Configuration > Policies > Windows Settings > Scripts (Logon/Logoff).
    3. Click on the "Show Files" button under the Logon Scripts section to open the Logon folder.
    4. Right-click inside the Logon folder and select New > Text Document.
    5. Rename the new text document to "Delete_Shortcuts.bat".
    6. Open the "Delete_Shortcuts.bat" file with a text editor (such as Notepad).
    7. Copy and paste the following code into the "Delete_Shortcuts.bat" file:

    @echo off

    for /f "delims=" %%i in ('dir /s /b "%USERPROFILE%*.lnk"') do (

    if "%%~nxi"=="<name_of_shortcut>.lnk" (

    echo Deleting shortcut: "%%i"

    del "%%i"

    )

    )

    1. Replace "<name_of_shortcut>" with the name of the executable that the shortcuts point to. For example, if the shortcuts point to "C:\Program Files\Microsoft Office\Office16\WINWORD.EXE", then replace "<name_of_shortcut>" with "WINWORD".
    2. Save and close the "Delete_Shortcuts.bat" file.
    3. Go back to the Group Policy Object editor and click on the "Add" button under the Logon Scripts section.
    4. Click on the "Browse" button and select the "Delete_Shortcuts.bat" file that you just created.
    5. Click on "OK" to save the changes.

    Now, every time a user logs in, the script will run and delete all shortcuts that point to the specified executable.

    For more Information, Please refer to following resources :-

    1. delete/update shortcut thru preferences - https://social.technet.microsoft.com/Forums/ie/23aafe2a-a1bb-4001-ad60-ed4565ac4e11/deleteupdate-shortcut-thru-preferences?forum=winserverGP
    2. Create a GPO to run only once to Delete desktop shortcuts - https://social.technet.microsoft.com/Forums/systemcenter/82c69e04-1232-41f4-9550-95ff96259672/create-a-gpo-to-run-only-once-to-delete-desktop-shortcuts?forum=winserverGP
    3. How to remove shortcut from \All Users\Desktop - https://social.technet.microsoft.com/Forums/exchange/cb240d02-d3ae-4694-802c-6e3be0c72c39/how-to-remove-shortcut-from-all-usersdesktop-when-you-know-the-shortcuts-target?forum=ITCG

    If you have any other questions or need assistance with anything, please don't hesitate to let me know. I'm here to help.

    If the reply was helpful, please don’t forget to upvote or accept as answer, thank you.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.