Batch file for deleting shortcuts

By sadj2885 ·
I am trying to create a batch file that will delete a specific shortcut on the desktop off of each users desktop. I know i can write a srcipt to delete it on startup, but that is not the best option for me. I need something i can double click on and it will search each users profile on the pc and delete the shortcut. Can this be done? Note: Writing a batch to delete it from "All Users" is not what im looking for.

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

What is the OS

by Jacky Howe In reply to Batch file for deleting s ...


@echo off
Set scut="C:\documents and settings"

del /s /q /f %scut%\name of shortcut.lnk


@echo off
Set scut=C:\users

del /s /q /f %scut%\name of shortcut.lnk

Edit: to add """

Collapse -

Just to be sure that you have the right .lnk

by Jacky Howe In reply to What is the OS

To obtain a list of Shortcuts from Documents and Settings run this. It will create a file on C> named SC.txt and it can be opened in NotePad.

@echo off
Set scut="C:\documents and settings"

dir /a /s %scut%\*.lnk >c:\sc.txt

Collapse -


by sadj2885 In reply to What is the OS

Sorry forgot to mention. Just tried it, worked beautifully. Just one more question, if i want to delete multiple shortcuts i just add "del /s /q /f %scut%\name of shortcut.lnk" on the next line correct? Or do i need to type set scut...

And thanks for the quick responses.

Collapse -

Not quite that simple

by Jacky Howe In reply to XP

@echo off
Set scut="C:\documents and settings"

del /s /q /f %scut%\100.lnk

goto A


Set scut="C:\documents and settings"

del /s /q /f %scut%\echo.txt.lnk

goto B


Set scut="C:\documents and settings"

del /s /q /f %scut%\Red Alert 3 Control Center.lnk

goto C


Set scut="C:\documents and settings"

del /s /q /f %scut%\history.lnk

goto end


The above sample will delete the first .lnk and then move on to the next command with the <b>goto</b> syntax and then delete the next .lnk and so on..........

You use the goto to go to the next set of instructions that you want to perform.

Depending on the amount of shortcuts that you want to remove will depend on the goto's that you will need to use. Also use the goto end to finish up the batch file. You could use wildcards but I find that it is dangerous and you could end up deleting all of the shortcuts.

<i>Keep us informed as to your progress if you require further assistance.</i>
<i>If you think that any of the posts that have been made by all TechRepublic Members, have solved or contributed to solving the problem, please Mark them as <b>Helpful</b> so that others may benefit from the outcome. </i> :-bd
<b>How do I rate the answers to my posted Question?</b>
Click on the answer. Click the Mark "Helpful" button displayed below the post. You may mark more than one answer as "Helpful."
The answers only have to be Helpful and don't necessarily have to be a definitive answer.

Collapse -

Here is an another alternative

by Jacky Howe In reply to Not quite that simple

You will need two files and if you do it this way you will only have to modify delSC.txt for future use. Make sure that the text in delSC.txt has the double quotes surrounding it.

Copy between the -------- and paste this into NotePad and save it as SCdel.cmd

Save both files to C> and you can create a shortcut to the files to run or modify them.


set target="C:\documents and settings"

FOR /F " tokens=* " %%i in (delSC.txt) do del /s /q /f %target%\%%i


Contents of delSC.txt

and so on.........

eXample of the output:

C>set target="C:\documents and settings"

C>FOR /F " tokens=* " %i in (delSC.txt) do del /s /q /f "C:\documents and settings"\%i

C>del /s /q /f "C:\documents and settings"\"t2.txt"
Deleted file - C:\documents and settings\Administrator\Desktop\t2.txt
Deleted file - C:\documents and settings\All Users\Desktop\t2.txt
Deleted file - C:\documents and settings\black\Desktop\t2.txt
Deleted file - C:\documents and settings\blank\Desktop\t2.txt
Deleted file - C:\documents and settings\dave\Desktop\t2.txt
Deleted file - C:\documents and settings\jock\Desktop\t2.txt
Deleted file - C:\documents and settings\Rob\Cookies\t2.txt
Deleted file - C:\documents and settings\Rob\Desktop\t2.txt

C>del /s /q /f "C:\documents and settings"\"t1.txt"
Deleted file - C:\documents and settings\Administrator\Desktop\T1.txt
Deleted file - C:\documents and settings\All Users\Desktop\T1.txt
Deleted file - C:\documents and settings\black\Desktop\T1.txt
Deleted file - C:\documents and settings\blank\Desktop\T1.txt
Deleted file - C:\documents and settings\dave\Desktop\T1.txt
Deleted file - C:\documents and settings\jock\Desktop\T1.txt
Deleted file - C:\documents and settings\Rob\Cookies\T1.txt
Deleted file - C:\documents and settings\Rob\Desktop\T1.txt

Press any key to continue . . .

Edit: modifed ws.txt to delSc.txt
and to add that it won't remove hidden links.

Collapse -

Just tried this...

by sadj2885 In reply to Here is an another altern ...

Set scut="C:\documents and settings"

del /s /q /f %scut%\"shortcut 1.lnk"

del /s /q /f %scut%\"shortcut 2.lnk"

del /s /q /f %scut%\"shortcut 3.lnk"


And it worked fine.

Collapse -

That's great [NT]

by Jacky Howe In reply to Just tried this...

Related Discussions

Related Forums