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!


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.

|improve this answer|||||
  • 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 May 9 '12 at 15:29
  • of course, but it may also be just fine for this purpose also :) Low-tech solutions save a lot of time over bothering to write up some logic in a script if it isn't really necessary. – August May 9 '12 at 15:44
  • Yes, but you didn't say that this would delete every file with that name. That's an important side effect. – wfaulk May 9 '12 at 15:46
  • 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.. – Jake A May 9 '12 at 15:47
  • 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? – Jesse Paxson May 9 '12 at 19:09

Maybe something like this?

for /D %%f in ("%1\*") do del "%%f\desktop\%2"

Save as a .bat and run something like this.

RemoveLnk.bat C:\Users Shortcut.lnk

This will go through C:\Users recursively and remove the specified shortcut from all users desktops.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.