We help IT Professionals succeed at work.

What script syntax to delete a file from all of the \\Documents and Settings desktops?

yuhs asked
Last Modified: 2010-04-16
VERY simple script, but I can't figure it out.

I want to deploy a script to my building to delete a particular icon from all the user desktops (XP machines). The icon I want to delete is not in the "All Users" profile, but is saved in individual user profiles. This script below works when I use it to delete the icon from the All Users, Default User, or my own desktop. But how do I script it to delete the icon from all the unknown profiles on the PC ?

This works:    del icon.url "\\%PC%\C$\Documents and Settings\all users\Desktop"
This doesn't:  del icon.url "\\%PC%\C$\Documents and Settings\%users%\Desktop"
Watch Question

You can use FOR /F to loop through subfolders of the Documents and Settings folder, as in the code below.  Change all instances of %%G to %G if you're running it from the command line rather than in a batch script.

See here for a good explanation of FOR /F:

for /F "tokens=* usebackq" %%G in (`dir "\\%PC%\C$\Documents and Settings" /A:D /B`) do (
 del "\\%PC%\C$\Documents and Settings\%%G\Desktop\icon.url"

Open in new window

This one is on us!
(Get your first solution completely free - no credit card required)

^ ... even if icon.url does not exist in the "Documents and Settings" folder, but only it its sub-folders, the command above will delete this file from all the sub-folders.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.