RogueSpear Posted October 12, 2004 Share Posted October 12, 2004 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 ExplicitOn Error Resume NextDim ws, fs, sysdrvSet 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 NextEnd 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 NextEnd SubCompressProgFilesCompressWindowFilesPlease 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 More sharing options...
CoffeeFiend Posted October 12, 2004 Share Posted October 12, 2004 Hmm, I don't really have a use for it, but I just had to say... Nice to see another vbscript/WMI addict here Link to comment Share on other sites More sharing options...
chrno2004 Posted October 26, 2004 Share Posted October 26, 2004 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? Link to comment Share on other sites More sharing options...
RogueSpear Posted October 26, 2004 Author Share Posted October 26, 2004 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now