Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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|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
    
It worked like a charm! Many thanks!!! –  Jake A May 9 '12 at 18:39

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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