Rob van der Woude's Scripting Pages

VBScript Scripting Techniques > Files > CAB Files

CAB Files

  1. Create CAB files with MakeCab
  2. Extract CAB files with System.Shell Folders' CopyHere method


VBScript Code:
CabCreate "D:\", Array( "D:\test.bat", "D:\Test.pdf" )

Sub CabCreate( myCabFile, arrFiles )
' This function creates a CAB file and adds a
' number of files from an array to the CAB file.
' Arguments:
' myCabFile    The fully qualified path for the CAB file to be created
' arrFiles     An array of fully qualified paths of the files to be added
' Requirements:
' MakeCab requires .NET FrameWork 2.0 or later
' Based on a script by Rinaldo Ferreira
' Written by Rob van der Woude
    Dim i, objCab, objFSO
    Set objFSO = CreateObject( "Scripting.FileSystemObject" )
    Set objCab = CreateObject( "MakeCab.MakeCab.1" )
    ' CStr() is necessary, because MakeCab object
    ' only accepts string arguments, not variants
    objCab.CreateCab CStr( myCabFile ), False, False, False
    For i = 0 To UBound( arrFiles )
        objCab.AddFile CStr( arrFiles(i) ), _
                       CStr( objFSO.GetFileName( arrFiles(i) ) )
End Sub
Windows version: 2000, XP, Server 2003, or Vista
Network: any
Client software: .NET FrameWork 2.0
Script Engine: any
Summarized: Works in Windows 2000 or later with .NET FrameWork 2.0 or later installed.
[Back to the top of this page]

page last uploaded: 2017-07-06, 12:38