サンプルでは、ローカルコンピュータですが、リモートコンピュータへの接続処理を追加すれば、リモートでの検索も可能だと思います(未確認)。 WQL(SQL for WMI) で注意するのは、通常のプログラミング言語と同じで、\ を \\ で表現するところです。 CIM_DataFile class
strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colFiles = objWMIService. _ ExecQuery("Select * From CIM_DataFile Where FileName = 'readme' and Extension = 'txt' and Name like 'C:\\backup%'") Wscript.Echo "件数 : " & colFiles.Count if colFiles.Count <> 0 then For Each objFile in colFiles Wscript.Echo "-------------------------------------" Set Props = objFile.Properties_ For Each Prop in Props if not isArray( Prop.Value ) then Wscript.Echo Prop.Name & " : " & Prop.Value else Wscript.Echo Prop.Name end if Next Next end if
実行は、必ずコマンドプロンプトから行います 例) cscript ファイル検索.vbs > flles.log 以下が出力の一件分です。
------------------------------------- AccessMask : 18809343 Archive : True Caption : c:\backup\readme.txt Compressed : False CompressionMethod : CreationClassName : CIM_LogicalFile CreationDate : 20140830131541.520550+540 CSCreationClassName : Win32_ComputerSystem CSName : COMPNAME Description : c:\backup\readme.txt Drive : c: EightDotThreeFileName : c:\backup\readme.txt Encrypted : False EncryptionMethod : Extension : txt FileName : readme FileSize : 58 FileType : Text Document FSCreationClassName : Win32_FileSystem FSName : NTFS Hidden : False InstallDate : 20140830131541.520550+540 InUseCount : LastAccessed : 20140830131541.520550+540 LastModified : 20140830131555.161330+540 Manufacturer : Name : c:\backup\readme.txt Path : \backup\ Readable : True Status : OK System : False Version : Writeable : True
【VBScript関連のカテゴリ】