Script to delete Shortcut on each user's desktop

9,731

why a script? if this is just 1 terminal server you should just be able to run:

forfiles /P c:\users /s /m shortcut.lnk /c "cmd /c del @path"

then add the shortcut back to the public desktop.

EDIT: Well that will teach me to post a command that doesn't work... Seemed like it would though... Anyway, I updated with a command that will work. You may have to run from an administrative command prompt though. NOTE (from comments on this answer): this will also delete the shortcut.lnk file anywhere under the c:\users directory structure. You can change the "del @path" to "dir @path" to make sure of the files before deleting them.

Share:
9,731

Related videos on Youtube

Jake A
Author by

Jake A

Updated on September 18, 2022

Comments

  • Jake A
    Jake A over 1 year

    I'm looking for a script to remove a .lnk file that was placed on every user's desktop. I installed a program on a terminal server that put a .lnk file on every user's desktop, rather than putting one shortcut in the "Public" desktop folder. I have since removed the program, but now I need a script to remove the shortcut from each user's desktop. Any help is much appreciated, thanks!

  • wfaulk
    wfaulk almost 12 years
    That will also remove any other files with the same name anywhere in the C:\Users hierarchy. This may not be what he wants.
  • wfaulk
    wfaulk almost 12 years
    Yes, but you didn't say that this would delete every file with that name. That's an important side effect.
  • Jake A
    Jake A almost 12 years
    I tried to run this command and it asked me if I wanted to also delete some unrelated files. It doesn't seem to be working..
  • Jesse Paxson
    Jesse Paxson almost 12 years
    I personally feel that this solution is a bit invasive for my tastes. The solution I offered works for only the shortcut you specify, so long as it is on the users desktop. Did my solution not work for you?