Jump to content

Compressing Directories with VBscript


Recommended Posts

I know that this can be done in batch quite easily, but what can I say? I'm a VBscripting weenie. I'm just more comfortable in that environment and whenever possible I try to avoid using ws.Run in favor of native code.

I run into enough machines that still have a pretty dinky hard drive but are otherwise perfectly viable XP machines. So I have implemented this as part of my post setup routine. I use this just prior to an initial hard disk defrag and then setting a static size page file. This gives the best chance of having a completely non-fragmented pagefile on those HD space challenged computers.

Option Explicit

On Error Resume Next

Dim ws, fs, sysdrv

Set ws = WScript.CreateObject("WScript.Shell")

Set fs = CreateObject("Scripting.FileSystemObject")

sysdrv = ws.ExpandEnvironmentStrings ("%SYSTEMDRIVE%")

'**********************************************************************

'** Subroutine; Compress selected directories In C:\Program Files    **

'**********************************************************************

Sub CompressProgFiles

Dim strComputer, objWMIService, ProgFileDir, ProgFileDirs, Directory, Target, sFolder, sFolders

strComputer = "."

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

ProgFileDir = sysdrv & "\\Program Files\\"

ProgFileDirs = Array("CMAK", "ComPlus Applications", "EuroTool", "HighMAT CD Writing Wizard", _

  "Microsoft ActiveSync", "microsoft frontpage", "Microsoft Visual Studio", "Microsoft Works", _

  "Movie Maker", "msn gaming zone", "NetMeeting", "Outlook Express", "Reference", "TermLite", _

  "Uninstall Information", "Windows Journal Viewer", "Windows NT", "Windows Update", "xerox")

For Each Directory In ProgFileDirs

  Target = (ProgFileDir + Directory)

  Set sFolders = objWMIService.ExecQuery ("Select * FROM Win32_Directory WHERE Name = '" & Target & "'" )

  For Each sFolder In sFolders

sFolder.Compress

  Next

Next

End Sub

'**********************************************************************

'** Subroutine; Compress selected directories In C:\Windows          **

'**********************************************************************

Sub CompressWindowFiles

Dim strComputer, objWMIService, WindowDir, WindowDirs, Directory, Target, sFolder, sFolders

strComputer = "."

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

WindowDir = sysdrv & "\\Windows\\"

WindowDirs = Array("addins", "Config", "Connection Wizard", "inf", "msapps", "repair", _

"RegisteredPackages", "Resources", "system", "twain_32", "Web")

For Each Directory In WindowDirs

  Target = (WindowDir + Directory)

  Set sFolders = objWMIService.ExecQuery ("Select * FROM Win32_Directory WHERE Name = '" & Target & "'" )

  For Each sFolder In sFolders

sFolder.Compress

  Next

Next

End Sub

CompressProgFiles

CompressWindowFiles

Please note that the double whacks (\\Program Files\\ and \\Windows\\) are necessary since we are using WMI. That's why I didn't simply use the common environment variables for each.

Link to comment
Share on other sites


  • 2 weeks later...

WMI is just the mechanism for compressing the folders. I tried my best to select directories where I thought that performance would be impacted the least. I am by no means the foremost expert on which are or are not the most important to performance.

If anyone has any suggestions for better selecting which directories to compress or not compress, I'm open for suggestions.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...