Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. sDeleteFolder = "Test"
  2. Set oFS = CreateObject("Scripting.FileSystemObject")
  3. Set dUSBKeys = ScanForUSBKeys()
  4. For Each oUSBKey in dUSBKeys.Keys
  5. If Left(oUSBKey, 1) = "" Then
  6. sKey = oUSBKey
  7. Else
  8. sKey = oUSBKey & ""
  9. End If
  10. oFS.DeleteFolder sdeleteFolder, sKey
  11. Next
  12. Set dUSBKeys = Nothing
  13. Set oFS = Nothing
  14.  
  15. MsgBox "Done Del all the folder from USB Drivs", vbOKOnly+VBINformation+VBSystemModal, "DONE"
  16. Function ScanForUSBKeys()
  17. Set oWMI = GetObject("winmgmts:\.rootcimv2")
  18. Set dTemp = CreateObject("Scripting.Dictionary")
  19. Set cDisks = oWMI.ExecQuery("Select InterfaceType,MediaType,PNPDeviceID,DeviceID,Size from Win32_DiskDrive")
  20. For Each oDisk in cDisks
  21. If InStr(LCase(oDisk.InterfaceType),"usb") > 0 AND InStr(LCase(oDisk.MediaType),"removable") > 0 _
  22. AND InStr(LCase(oDisk.PNPDeviceID),"blackberry") = 0 AND InStr(LCase(oDisk.PNPDeviceID),"ipod") = 0 _
  23. AND NOT oDisk.PNPDeviceID = "" Then
  24. Set cDrivePartitions = oWMI.ExecQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" & _
  25. oDisk.DeviceID & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition" )
  26. For Each oDrivePartition in cDrivePartitions
  27. Set cDriveLetters = oWMI.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & _
  28. oDrivePartition.DeviceID & "'} WHERE AssocClass = Win32_LogicalDiskToPartition")
  29. For Each oDriveLetter in cDriveLetters
  30. dTemp.Add oDriveLetter.DeviceID, 1
  31. Next
  32. Set cDriveLetters = Nothing
  33. Next
  34. Set cDrivePartitions = Nothing
  35. End If
  36. Next
  37. Set cDisks = Nothing
  38. Set ScanForUSBKeys = dTemp
  39. Set dTemp = Nothing
  40. Set oWMI = Nothing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement