Link to home
Start Free TrialLog in
Avatar of mdlp
mdlpFlag for United States of America

asked on

VBscript crashes on "FOR" statment

Thank you for your time in advance,
the following script crashes at the FOR Each with the following error
error 0x80041017
code 80041017
source (null)

I assume it means that the query it is not finding the Dxxver in any file name in the folder C:\Program Files\Review\.  I have the file in place, it is not hidden and not read only. The script resides in the same folder and I have administrator rights to the folder.   I have to use a inStr because the file name will change and this is the static part of the name.  I have tested the function getpath and will want to replace the hard code of the path in the final code.  
I am at a loss, if you can see anything wrong or a different way to do the same process it would get this project back on its feet. I am not tied to this process.

Function GetPath
' Return path to the current script
DIM path
path = WScript.ScriptFullName  ' script file name
GetPath = Left(path, InstrRev(path, "\"))
End Function

dim strComputer
dim objWMIService
dim colFileList

strComputer = "."

      ' connect to wmi
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'***********
      ' collect list of files that have "DxxVer" in it- must be only one
      Wscript.Echo "file Pathe name = :" & getpath()

      Set colFileList = objWMIService.ExecQuery _    
      ("ASSOCIATORS OF {Win32_Directory.Name='""C:\Program Files\Review\""'} Where " _        
            & "ResultClass = CIM_DataFile")

      For Each objFile In colFileList    
            If InStr(objFile.FileName, "DxxVer") Then        
                  Wscript.Echo "file name = :" & objFile.FileName  
            End If
      Next
Wscript.Quit
'************

Thank very much!
mdlp
ASKER CERTIFIED SOLUTION
Avatar of Robberbaron (robr)
Robberbaron (robr)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mdlp

ASKER

Thank mate, and good on you!!
this was a great help.
I did find that to pass to the compare, the file name has to be in lower case, i noticed that all the names displayed are in lowercase, but the compare side is case sensitive.   As soon as I changed the name of the file to all lower case the script found the name.
Again thank you very much and you deserve the 500 points.  
mdlp