1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
strFolderName = "C:\Temp"
Set colSubfolders = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='" & strFolderName & "'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile in colFiles
If UCase(objFile.Extension) = "VBS" Then
WScript.Echo strFolderName & "\" & objFile.FileName & "." & objFile.Extension
objFile.Delete
End If
Next
For Each objFolder in colSubfolders
GetSubFolders strFolderName
Next
Sub GetSubFolders(strFolderName)
Set colSubfolders2 = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
For Each objFolder2 in colSubfolders2
strFolderName = objFolder2.Name
Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='" & strFolderName & "'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile in colFiles
If UCase(objFile.Extension) = "VBS" Then
WScript.Echo strFolderName & "\" & objFile.FileName & "." & objFile.Extension
objFile.Delete
End If
Next
GetSubFolders strFolderName
Next
End Sub |
Partager