Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

objWMIService.ExecQuery CIM_DataFile with LIKE fails ERROR 80041017

Status
Not open for further replies.

Boeboes

Technical User
Nov 2, 2006
2
NL
Hi,

I want to delete files with a specific filename pattern older than a specific date. I search for the files with a query and check "lastmodified".
It worked fine on my XP system but when I run it on an W2K server it fails.
Boils down to a problem with the query:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService. _
ExecQuery("Select * from CIM_DataFile where drive='C:' and path = '\\' and name LIKE 'c:\\moremem.b%' ")

For Each objFile in colFiles
Wscript.Echo objFile.Name & " -- " & Left (objfile.lastmodified,8)
Next

On the W2K The query crashes and I get an error 80041017
When I change the "LIKE" to an "= 'c:\\moremem.bat' it does find the file.

Anyone got an idea what is wrong ?

Regards,
Boeboes
 
Yes. OS version. Some WQL commands are not available in Windows 2000. I don't believe that the LIKE operator was introduced until WinXP/2003.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
PScottC is right on this, there is a MS article on it
 
Thanks, at least I don't have to look where I went wrong anymore.

Can anyone point me to some good documentation places.

When I wanted to code around it I decided to get all file name s and select the pattern myself "left(objFile.FileName,10)" but then there are versions that don't implement objFile.FileName.
Seems that objFile.Name is implemented in most versions so changed it to "instr(objFile.Name, <pattern>) <> 0".

BUT I'm getting tired of all these different version, is there good documentation so I can predict these issues.

Boeboes
 
dont bother with .Any property of files, Just use (objFile, <pattern>) objFile will implicitly expose its name for you. but .Name should be ok for all stuff, im not aware of many changes in the scripting host. if you are doing this in an environment then should be able to update all machine to a certain version of the scripting host?
i think in general it will just come down to pure testing effort, get yourself a bank of all the OS's you support, perhaps virtual, and then test all your scripts against all the machines.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top