Discussion:
New to WMIC
(too old to reply)
RayRedSox
2009-10-20 21:13:46 UTC
Permalink
I'm trying to write a batch file using WMIC to delete files out of th
windows\temp folder on a remote server. So far I've done the following
but it keeps saying invalid query:

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
drive, hence the reason for the %WINDIR%. Can I use parentheses in WMI
command?

Thank you

--
RayRedSo
-----------------------------------------------------------------------
RayRedSox's Profile: http://forums.techarena.in/members/146555.ht
View this thread: http://forums.techarena.in/server-scripting/1260829.ht

http://forums.techarena.i
Pegasus [MVP]
2009-10-20 21:32:31 UTC
Permalink
I'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
Since you're writing a batch file, why not use the simple approach and stick
to batch file commands?
@echo off
del /q /f %Winddir%\temp\*.tmp
RayRedSox
2009-10-20 22:44:37 UTC
Permalink
Thanks, perhaps I'm overcomplicating this...the server that I am tryin
to delete these files on is remote...in other words, prior to thi
command, I'm querying a SQL DB to get a list of servers, then using WMI
to delete the items in the temp folder for each server. Can I do tha
using your approach?

Thanks again for your help

--
RayRedSo
-----------------------------------------------------------------------
RayRedSox's Profile: http://forums.techarena.in/members/146555.ht
View this thread: http://forums.techarena.in/server-scripting/1260829.ht

http://forums.techarena.i
Pegasus [MVP]
2009-10-21 09:59:11 UTC
Permalink
No, you did not overcomplicate things but I missed the "remote" bit. I don't
know much about WMIC, so I can't help you there, but you could use the
following batch file to achieve your aim. It is based on a VB Script.
Alternatively you could invoke the underlying script file directly.

Batch file
[01] @echo off
[02] set PC=sup24app01
[03] set Scr=c:\TempVBS.vbs
[04] set VB=echo^>^>%Scr%
[05] cd 1>nul 2>%Scr%
[06] %VB% Set oFSO = CreateObject("Scripting.FileSystemObject")
[07] %VB% Set oWMIService = GetObject("winmgmts:\\%PC%\root\cimv2")
[08] %VB% Set cItems = oWMIService.ExecQuery("Select * From
Win32_OperatingSystem")
[09] %VB% For Each oItem In cItems
[10] %VB% oFSO.DeleteFile oItem.WindowsDirectory ^& "\temp\*.tmp"
[11] %VB% Next
[12] cscript //nologo %Scr%
[13] del %Scr%

Script file
[1] Set oFSO = CreateObject("Scripting.FileSystemObject")
[2] Set oWMIService = GetObject("winmgmts:\\sup24app01\root\cimv2")
[3] Set cItems = oWMIService.ExecQuery("Select * From
Win32_OperatingSystem")
[4] For Each oItem In cItems
[5] oFSO.DeleteFile oItem.WindowsDirectory & "\temp\*.tmp"
[6] Next
Thanks, perhaps I'm overcomplicating this...the server that I am trying
to delete these files on is remote...in other words, prior to this
command, I'm querying a SQL DB to get a list of servers, then using WMIC
to delete the items in the temp folder for each server. Can I do that
using your approach?
Thanks again for your help.
--
RayRedSox
------------------------------------------------------------------------
RayRedSox's Profile: http://forums.techarena.in/members/146555.htm
View this thread: http://forums.techarena.in/server-scripting/1260829.htm
http://forums.techarena.in
Al Dunbar
2009-10-21 02:08:23 UTC
Permalink
I'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 pretty rusty on WMIC syntax, but I would suggest the issue is the
construction of the WMIC command rather than any lack of query results.
I'm taking precautions in case the windows temp folder is not on the C
drive, hence the reason for the %WINDIR%.
If you run the WMIC command as shown on your local computer, it is the
command processor on your local computer that is going to substitute the
value of its WINDIR variable _before_ sending the command to the remote
system. You _might_ be able to pass the variable reference to the remote
system by doubling the percent signs, i.e.:

WMIC /node:sup24app01 path cim_datafile WHERE "path='%%WINDIR%%\\TEMP\\'
AND Extension ='tmp'" delete
Can I use parentheses in WMIC
command?
Parentheses are generally interpreted by CMD.exe, so this is perfectly
acceptable:

(WMIC /node:sup24app01 path cim_datafile WHERE
"path='%%WINDIR%%\\TEMP\\' AND Extension ='tmp'" delete)

Of course, that does basically the same as the command without parens. If
you want parens to be passed to the executable to process you will have to
take syntactical steps. But before doing that, you should determine if WMIC
will process the parens in the way you think it will.

/Al
Thank you.
--
RayRedSox
------------------------------------------------------------------------
RayRedSox's Profile: http://forums.techarena.in/members/146555.htm
View this thread: http://forums.techarena.in/server-scripting/1260829.htm
http://forums.techarena.in
Loading...