Compress a Volume (VBScript)

This code can be found in Chapter 7 of Windows XP Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' From the book, "Windows XP Cookbook"
' ISBN: 0596007256

' ------ SCRIPT CONFIGURATION ------
strComputer = "."
strDrive = "<Drive>" ' e.g. D:
boolRecursive = True
' ------ END CONFIGURATION ---------
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colFolder = objWMI.ExecQuery("select * from Win32_Directory " & _
 " where name = '" & strDrive & "\\'")
if colFolder.Count <> 1 then
 WScript.Echo "Error: Volume not found."
else
 for each objFolder in colFolder
 intRC = objFolder.CompressEx(strErrorFile,,boolRecursive)
 if intRC <> 0 then
 WScript.Echo "Error compressing volume: " & intRC 
 WScript.Echo "Stopped on file: " & strErrorFile
 else
 WScript.Echo "Successfully compressed volume."
 end if
 next 
end if

This code has been viewed 777 times.

New from the creators of TechTasks.com: StatSheet.com