Solved

Use WMIC command to delete folder, subfolders and/or files

Posted on 2010-11-22
3
3,212 Views
Last Modified: 2012-05-10
I have successfully used the command below in a batch file to get WMIC to delete *.tmp files from the %WINDIR%\TEMP folder on all named workstations on the network running XP. I haven't tested other versions but I assume that, given the age of WMIC, it'll work in later versions of Windows.

WMIC /node:Computer01,Computer02,Computer03 path cim_datafile WHERE "path='%%WINDIR%%\\TEMP\\' AND  Extension ='tmp'" delete

Open in new window


Additionally, I would like to delete some Start menu folders (and some shortcuts if possible) on all the computers on the network named in the "node" portion of the command. I'm a little rusty on the WMIC commands; is there a way to specify the path to the All Users' Start menu and delete a subfolder (and its contents) if the folder name matches a string? And is it possible to delete shortcuts if their file name matches a string)?

Ideally, I'd like the following subfolders (and any files contained within them):
C:\Documents and Settings\All Users\Start Menu\Programs\Microsoft Office\
C:\Documents and Settings\All Users\Start Menu\Programs\Microsoft Silverlight\
C:\Documents and Settings\All Users\Start Menu\Programs\Sophos\

and the following files:
C:\Documents and Settings\All Users\Start Menu\Programs\Acrobat.com.lnk
C:\Documents and Settings\All Users\Start Menu\Programs\Adobe Reader X.lnk
C:\Documents and Settings\All Users\Start Menu\Programs\HP Help and Support.lnk

...deleted from the Start menu of each named computer on the network.

I'm aware that this is a resource-intensive operation (particularly as there are may other folders I'd like to add to that list), but I plan on running this during network downtime so as not to slow the computers down when in use. My ultimate intention is to clear the clutter of our users' Start menus on the 400+ computers on the network without having to do so manually; I know how to set the node to read from a list in an external text file, as in:
WMIC /failfast:on /node:@"FILENAME.txt"

Open in new window

Many thanks in advance.
0
Comment
Question by:skrysiak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 20

Expert Comment

by:alainbryden
ID: 34196453
%TEMP% will take you to C:\Documents and Settings\username\Local Settings\Temp or equivalent
%ALLUSERSPROFILE% to C:\Documents and Settings\All Users or equivalent
More environment variables can be found here: http://vlaurie.com/computers2/Articles/environment.htm

also note that when using [Extension ='tmp'] - you may actually want just those files, but these temporary folders will be filled with tons of temporary files that don't have this extension. If you're doing a cleanup, you might want to be a little more generous with your file selection.



On a separate note, if you're using a batch file anyways, why not just use batch file commands?
@echo off
del  /q  /f  %Winddir%\temp\*.tmp
0
 
LVL 20

Accepted Solution

by:
alainbryden earned 500 total points
ID: 34196514
See if the following works first:

Make a text file 'Workstations.txt':
-----------
COMPUTER01
COMPUTER02
COMPUTER03
_______

And in your batch file:
for /f %%i in (Workstations.txt) do del \\%%i\%WINDIR%\TEMP\*.tmp


Also note that in any of these cases %WINDIR% is an environment variable on your computer, and it's probably just subbing in the string "C:\WINDOWS" into your query, not actually checking what the windows directory is on that particular machine : /
0
 

Author Closing Comment

by:skrysiak
ID: 34207606
Didn't know you could use external files in this way! Many thanks for your help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question