Post by Tom LavedasPost by Tom LavedasPost by RayRedSoxI'm trying to write a batch file using WMIC to delete files out of the
windows\temp folder on a remote server. So far I've done the following,
WMIC /node:sup24app01 path cim_datafile WHERE "path='%WINDIR%\\TEMP\\'
AND Extension ='tmp'" delete
I'm taking precautions in case the windows temp folder is not on the C
drive, hence the reason for the %WINDIR%. Can I use parentheses in WMIC
command?
Thank you.
--
RayRedSox
------------------------------------------------------------------------
RayRedSox's Profile:http://forums.techarena.in/members/146555.htm
View this
thread:http://forums.techarena.in/server-scripting/1260851.htm
http://forums.techarena.in
The SQL syntax is VERY particular. The PATH specification must be just
that, it cannot contain the drive letter. Plus, your original was not
escaping all of the backslashes. This is the way it worked for me ...
set tmp=%WINDIR:~2%\
set qry="drive='%WINDIR:~0,2%' and path='%tmp:\=\\%' and
extension='tmp'"
WMIC /node:'sup24app01' path cim_datafile WHERE %qry% delete
Note that I also had to enclose the machine ID in single quote marks
for it to work for me.
_____________________
Tom Lavedas
It occurred to me just after I posted that this approach still has a
fatal flaw. That is that the WINDIR variable needs to be determined
for the target machine. The way it is written, it is accessing the
local machine's environment, not the target machine. So I tried this
query to get the information from the target machine ...
set compname=sup24app01
set qry="name='windir'"
WMIC /node:'%compname%' environment WHERE %qry% get 'VariableValue' /
value
For my local machine test (I don't have domain admin privileges here),
the result was ...
VariableValue=%SystemRoot%
Which is not helpful. So I altered the query to request the
SystemRoot value instead and received a 'No Instance(s) Available.'
for my troubles. I don't know why this happened and I have not yet
figured out how to work around this problem. Maybe someone else does.
_____________________
Tom Lavedas
I think I have a viable solution now using the Win32_OperatingSystem
class instead ...
@echo off
setlocal
set compname=sup24app01
for /f "usebackq tokens=2 delims==" %%a in (
`WMIC /node:'%compname%' os get 'WindowsDirectory' /value`
) do set _WinDir=%%a
set _drv=%_WinDir:~0,2%
set _path=%_WinDir:~2%\temp\
set qry="drive='%_drv%' and path='%_path:\=\\%' and extension='tmp'"
WMIC /node:'%compname%' path cim_datafile WHERE %qry% delete
I did run into a 'Generic Error' when the procedure tried to delete a
file that was attached to a running process. I think the only way
around that is to get a list of the matching files and then work
through the list one file at a time, deleting them in turn.
Otherwise, the process is aborted at the first error, which may miss
files listed after the one in use. That is an exercise best left to
the student ;)
_____________________
Tom Lavedas
=============
I tried your routine on a Win2000 machine. It works very well. Unfortunately
it is very slow, taking 8 seconds to execute. The VB Script I suggested
takes 1 second, but only when I remove the error I have discovered just now.