Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Compressing Directories with VBscript

Featured Replies

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.

Hmm, I don't really have a use for it, but I just had to say... Nice to see another vbscript/WMI addict here :lol:

  • 2 weeks later...

Sorry I didn't quite understand why you are compressing the folders here. Is it something to do with WMI or was it just to save hdd space? Are there any speed/performance impact on compressing these folders?

  • Author

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.

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.