WQL and Path

I am playing around with WQL today. For a longest time, I couldn’t get this query to work.

Set colFiles = objWMIService.ExecQuery ("SELECT * FROM CIM_DataFile" &  _

   " WHERE Drive = 'c:' AND Extension = 'mdb' And Path = '\\windows\\' ")

Have you noticed anything wrong with the query? It’s the Path! I found that you need to use double back slash instead of single back slash. So, the correct Query should be like this.

Set colFiles = objWMIService.ExecQuery ("SELECT * FROM CIM_DataFile" &  _

   " WHERE Drive = 'c:' AND Extension = 'mdb' And Path = '\\\\windows\\\\' ")

Also, I found that if you have “!=” in your query, the query runs very very slowly.

WMI script to find files last accessed on a certain date

dtDate = "5/2/2005"

strSearchFolder = "C:Windows"



Set objFSO = CreateObject("Scripting.FileSystemObject")

WScript.Echo "File(s) last accessed on: " & dtDate & " in: " & strSearchFolder

EnumAndCheckFiles objFSO.GetFolder(strSearchFolder), dtDate



Sub EnumAndCheckFiles(objFolder, dtDate)

    Set objFiles = objFolder.Files

    For Each objFile in objFiles

    CheckFile objFile, dtDate

    Next

    For Each objSubfolder in objFolder.SubFolders

        EnumAndCheckFiles objSubfolder, dtDate

    Next

End Sub



Sub CheckFile(objFile, dtDate)

    If DateDiff("d", objFile.DateLastAccessed, dtDate) = 0 Then

        WScript.Echo objFile.Path

    End if

End Sub

WMI and Day Light saving time

If you use the "Bias" property of Win32_TimeZone to convert time to UTC time, remember to check "DayLightInEffect" property of Win32_ComputerSystem to determine if you need to adjust the "Bias" according to Day Light saving time.

Translator

English flagItalian flagKorean flagChinese (Simplified) flagChinese (Traditional) flagPortuguese flagGerman flagFrench flagSpanish flagJapanese flagArabic flagRussian flagGreek flagDutch flagBulgarian flagCzech flagHindi flagRomanian flagSwedish flagHebrew flagHungarian flag

Archives