Set objFSO = CreateObject("Scripting.FileSystemObject") Set objOutputFile = objFSO.CreateTextFile("output.txt")
strComputer = "." Set objWMIService = GetObject("winmgmts:\\" strComputer "\root\cimv2")
Set FileList = objWMIService.ExecQuery _ ("ASSOCIATORS OF {Win32_Directory.Name='C:\Logs'} Where " _ "ResultClass = CIM_DataFile")
For Each objFile In FileList Set objTextFile = objFSO.OpenTextFile(objFile.Name, ForReading) strText = objTextFile.ReadAll objTextFile.Close objOutputFile.WriteLine strText Next
objOutputFile.Close
實際上,我們在此處執(zhí)行的全部操作是獲取 C:\Logs 文件夾中所有文件的集合;這是通過以下 WMI Associators of 查詢實現(xiàn)的:
Set FileList = objWMIService.ExecQuery _ ("ASSOCIATORS OF {Win32_Directory.Name='C:\Logs'} Where " _ "ResultClass = CIM_DataFile")