Batch file help: Use wildcard in directory?

Tangent

[H]ard|Gawd
Joined
Jan 7, 2002
Messages
1,482
Background: At my work pretty much all users have admin rights to their PC. (That issue's above my paygrade otherwise it wouldn't be this way...) Some sections have PCs that are used by several different users during the course of the week. The problem is that there are a few people that have a bad habit of dragging shortcuts from the all users desktop to their individual desktops. (Windows XP environment by the way) This means that on a regular basis I get helpdesk tickets from the other users that are now missing the shortcut. (Trying to enforce a no delete/move policy is out of the question, our authority has been neutered around here...)

Instead of constantly manually fixing this by dragging a shortcut to the All Users desktop and then manually browsing through up to 20 individual desktops to delete the one they dragged there (because naturally if they see 2 shortcuts they'll manage to delete the All Users one every time) I'm writing a simple batch file that'll do of all the common fixes at once.

Problem: I can't figure out an easy way for a batch file to delete all shortcuts of a specific name from each individual desktop without adding a line for each and every user name. "C:\Documents and Settings\*\Desktop\shortcut.lnk" doesn't work, it doesn't like the "*" wildcard. Is there any way to do what I'm attempting?

Thanks
 
Won't that just return the currently logged on username? I want to be able to delete it from every user's desktop at once...
 
This will do what you want.

In the "c:\documents and settings" folder create a batch file called notallusers.bat (returns all profile directory names except All Users):
Code:
dir /b /ad | find /i /v "All Users"

Then create another batch file (any name you want) in the same directory to delete the shortcuts containing this:
Code:
for /f %%1 in ('notallusers.bat') do del "c:\documents and settings\%%1\shortcut.lnk"

If you want to delete more links in the second file, just keep adding lines.
 
Back
Top