<p>Is the ZIP compression that is built into Windows XP/Vista/2003/2008 able to be scripted at all? What executable would I have to call from a BAT/CMD file? or is it possible to do it with VBScript?</p>

<p>I realize that this is possible using <a href="http://en.wikipedia.org/wiki/WinZip" rel="noreferrer">WinZip</a>, <a href="http://en.wikipedia.org/wiki/7-Zip" rel="noreferrer">7-Zip</a> and other external applications, but I'm looking for something that requires no external applications to be installed.</p>

[{'answer_id': 30369, 'author': 'brian newman', 'author_id': 3210, 'author_profile': 'https://Stackoverflow.com/users/3210', 'pm_score': 1, 'selected': False, 'text': '<p>There are both zip and unzip executables (as well as a boat load of other useful applications) in the UnxUtils package available on SourceForge (<a href="http://sourceforge.net/projects/unxutils" rel="nofollow noreferrer">http://sourceforge.net/projects/unxutils</a>). Copy them to a location in your PATH, such as \'c:\\windows\', and you will be able to include them in your scripts.</p>\n\n<p>This is not the perfect solution (or the one you asked for) but a decent work-a-round.</p>\n'}, {'answer_id': 30473, 'author': 'Adam Davis', 'author_id': 2915, 'author_profile': 'https://Stackoverflow.com/users/2915', 'pm_score': 6, 'selected': True, 'text': '<p>There are VBA methods to <a href="http://www.rondebruin.nl/win/s7/win001.htm" rel="noreferrer">zip</a> and <a href="http://www.rondebruin.nl/win/s7/win002.htm" rel="noreferrer">unzip</a> using the windows built in compression as well, which should give some insight as to how the system operates.  You may be able to build these methods into a scripting language of your choice.</p>\n\n<p>The basic principle is that within windows you can treat a zip file as a directory, and copy into and out of it.  So to create a new zip file, you simply make a file with the extension <code>.zip</code> that has the right header for an empty zip file.  Then you close it, and tell windows you want to copy files into it as though it were another directory.</p>\n\n<p>Unzipping is easier - just treat it as a directory.</p>\n\n<p>In case the web pages are lost again, here are a few of the relevant code snippets:</p>\n\n<h1>ZIP</h1>\n\n<pre><code>Sub NewZip(sPath)\n\'Create empty Zip File\n\'Changed by keepITcool Dec-12-2005\n    If Len(Dir(sPath)) &gt; 0 Then Kill sPath\n    Open sPath For Output As #1\n    Print #1, Chr$(80) &amp; Chr$(75) &amp; Chr$(5) &amp; Chr$(6) &amp; String(18, 0)\n    Close #1\nEnd Sub\n\n\nFunction bIsBookOpen(ByRef szBookName As String) As Boolean\n\' Rob Bovey\n    On Error Resume Next\n    bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)\nEnd Function\n\n\nFunction Split97(sStr As Variant, sdelim As String) As Variant\n\'Tom Ogilvy\n    Split97 = Evaluate("{""" &amp; _\n                       Application.Substitute(sStr, sdelim, """,""") &amp; """}")\nEnd Function\n\nSub Zip_File_Or_Files()\n    Dim strDate As String, DefPath As String, sFName As String\n    Dim oApp As Object, iCtr As Long, I As Integer\n    Dim FName, vArr, FileNameZip\n\n    DefPath = Application.DefaultFilePath\n    If Right(DefPath, 1) &lt;&gt; "\\" Then\n        DefPath = DefPath &amp; "\\"\n    End If\n\n    strDate = Format(Now, " dd-mmm-yy h-mm-ss")\n    FileNameZip = DefPath &amp; "MyFilesZip " &amp; strDate &amp; ".zip"\n\n    \'Browse to the file(s), use the Ctrl key to select more files\n    FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xl*), *.xl*", _\n                    MultiSelect:=True, Title:="Select the files you want to zip")\n    If IsArray(FName) = False Then\n        \'do nothing\n    Else\n        \'Create empty Zip File\n        NewZip (FileNameZip)\n        Set oApp = CreateObject("Shell.Application")\n        I = 0\n        For iCtr = LBound(FName) To UBound(FName)\n            vArr = Split97(FName(iCtr), "\\")\n            sFName = vArr(UBound(vArr))\n            If bIsBookOpen(sFName) Then\n                MsgBox "You can\'t zip a file that is open!" &amp; vbLf &amp; _\n                       "Please close it and try again: " &amp; FName(iCtr)\n            Else\n                \'Copy the file to the compressed folder\n                I = I + 1\n                oApp.Namespace(FileNameZip).CopyHere FName(iCtr)\n\n                \'Keep script waiting until Compressing is done\n                On Error Resume Next\n                Do Until oApp.Namespace(FileNameZip).items.Count = I\n                    Application.Wait (Now + TimeValue("0:00:01"))\n                Loop\n                On Error GoTo 0\n            End If\n        Next iCtr\n\n        MsgBox "You find the zipfile here: " &amp; FileNameZip\n    End If\nEnd Sub\n</code></pre>\n\n<h1>UNZIP</h1>\n\n<pre><code>Sub Unzip1()\n    Dim FSO As Object\n    Dim oApp As Object\n    Dim Fname As Variant\n    Dim FileNameFolder As Variant\n    Dim DefPath As String\n    Dim strDate As String\n\n    Fname = Application.GetOpenFilename(filefilter:="Zip Files (*.zip), *.zip", _\n                                        MultiSelect:=False)\n    If Fname = False Then\n        \'Do nothing\n    Else\n        \'Root folder for the new folder.\n        \'You can also use DefPath = "C:\\Users\\Ron\\test\\"\n        DefPath = Application.DefaultFilePath\n        If Right(DefPath, 1) &lt;&gt; "\\" Then\n            DefPath = DefPath &amp; "\\"\n        End If\n\n        \'Create the folder name\n        strDate = Format(Now, " dd-mm-yy h-mm-ss")\n        FileNameFolder = DefPath &amp; "MyUnzipFolder " &amp; strDate &amp; "\\"\n\n        \'Make the normal folder in DefPath\n        MkDir FileNameFolder\n\n        \'Extract the files into the newly created folder\n        Set oApp = CreateObject("Shell.Application")\n\n        oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(Fname).items\n\n        \'If you want to extract only one file you can use this:\n        \'oApp.Namespace(FileNameFolder).CopyHere _\n         \'oApp.Namespace(Fname).items.Item("test.txt")\n\n        MsgBox "You find the files here: " &amp; FileNameFolder\n\n        On Error Resume Next\n        Set FSO = CreateObject("scripting.filesystemobject")\n        FSO.deletefolder Environ("Temp") &amp; "\\Temporary Directory*", True\n    End If\nEnd Sub\n</code></pre>\n'}, {'answer_id': 124775, 'author': 'Jay', 'author_id': 20840, 'author_profile': 'https://Stackoverflow.com/users/20840', 'pm_score': 5, 'selected': False, 'text': '<p>Yes, this can be scripted with VBScript. For example the following code can create a zip from a directory: </p>\n\n<pre><code>Dim fso, winShell, MyTarget, MySource, file\nSet fso = CreateObject("Scripting.FileSystemObject")\nSet winShell = createObject("shell.application")\n\n\nMyTarget = Wscript.Arguments.Item(0)\nMySource = Wscript.Arguments.Item(1)\n\nWscript.Echo "Adding " &amp; MySource &amp; " to " &amp; MyTarget\n\n\'create a new clean zip archive\nSet file = fso.CreateTextFile(MyTarget, True)\nfile.write("PK" &amp; chr(5) &amp; chr(6) &amp; string(18,chr(0)))\nfile.close\n\nwinShell.NameSpace(MyTarget).CopyHere winShell.NameSpace(MySource).Items\n\ndo until winShell.namespace(MyTarget).items.count = winShell.namespace(MySource).items.count\n    wscript.sleep 1000 \nloop\n\nSet winShell = Nothing\nSet fso = Nothing\n</code></pre>\n\n<p>You may also find <a href="http://www.naterice.com/blog/template_permalink.asp?id=64" rel="noreferrer">http://www.naterice.com/blog/template_permalink.asp?id=64</a> helpful as it includes a full Unzip/Zip implementation in VBScript.</p>\n\n<p>If you do a size check every 500 ms rather than a item count it works better for large files. Win 7 writes the file instantly although it\'s not finished compressing:</p>\n\n<pre><code>set fso=createobject("scripting.filesystemobject")\nSet h=fso.getFile(DestZip)\ndo\n    wscript.sleep 500\n    max = h.size\nloop while h.size &gt; max \n</code></pre>\n\n<p>Works great for huge amounts of log files.</p>\n'}, {'answer_id': 410470, 'author': 'Cheeso', 'author_id': 48082, 'author_profile': 'https://Stackoverflow.com/users/48082', 'pm_score': 3, 'selected': False, 'text': '<p>Just for clarity:  GZip is not an MS-only algorithm as suggested by Guy Starbuck in his comment from August. \nThe GZipStream in System.IO.Compression uses the Deflate algorithm, just the same as the zlib library, and many other zip tools.  That class is fully interoperable with unix utilities like gzip.</p>\n\n<p>The GZipStream class is not scriptable from the commandline or VBScript, to produce ZIP files, so it alone would not be an answer the original poster\'s request.  </p>\n\n<p>The free <a href="http://dotnetzip.codeplex.com" rel="nofollow noreferrer">DotNetZip</a> library does read and produce zip files, and can be scripted from VBScript or Powershell.  It also includes command-line tools to produce and read/extract  zip files. </p>\n\n<p>Here\'s some code for VBScript: </p>\n\n<pre><code>dim filename \nfilename = "C:\\temp\\ZipFile-created-from-VBScript.zip"\n\nWScript.echo("Instantiating a ZipFile object...")\ndim zip \nset zip = CreateObject("Ionic.Zip.ZipFile")\n\nWScript.echo("using AES256 encryption...")\nzip.Encryption = 3\n\nWScript.echo("setting the password...")\nzip.Password = "Very.Secret.Password!"\n\nWScript.echo("adding a selection of files...")\nzip.AddSelectedFiles("*.js")\nzip.AddSelectedFiles("*.vbs")\n\nWScript.echo("setting the save name...")\nzip.Name = filename\n\nWScript.echo("Saving...")\nzip.Save()\n\nWScript.echo("Disposing...")\nzip.Dispose()\n\nWScript.echo("Done.")\n</code></pre>\n\n<p>Here\'s some code for Powershell: </p>\n\n<pre><code>[System.Reflection.Assembly]::LoadFrom("c:\\\\dinoch\\\\bin\\\\Ionic.Zip.dll");\n\n$directoryToZip = "c:\\\\temp";\n$zipfile =  new-object Ionic.Zip.ZipFile;\n$e= $zipfile.AddEntry("Readme.txt", "This is a zipfile created from within powershell.")\n$e= $zipfile.AddDirectory($directoryToZip, "home")\n$zipfile.Save("ZipFiles.ps1.out.zip");\n</code></pre>\n\n<p>In a .bat or .cmd file, you can use the zipit.exe or unzip.exe tools.  Eg:</p>\n\n<pre><code>zipit NewZip.zip  -s "This is string content for an entry"  Readme.txt  src \n</code></pre>\n'}, {'answer_id': 15091022, 'author': 'lupok', 'author_id': 1866043, 'author_profile': 'https://Stackoverflow.com/users/1866043', 'pm_score': 1, 'selected': False, 'text': '<p>to create a compressed archive you can use the utility MAKECAB.EXE</p>\n'}, {'answer_id': 28088844, 'author': 'npocmaka', 'author_id': 388389, 'author_profile': 'https://Stackoverflow.com/users/388389', 'pm_score': 1, 'selected': False, 'text': '<p>Here\'a my attempt to summarize built-in capabilities windows for compression and uncompression  - <a href="https://stackoverflow.com/questions/28043589/how-can-i-compres-zip-and-uncopress-unzip-files-and-folders-with-batch-f">How can I compress (/ zip ) and uncompress (/ unzip ) files and folders with batch file without using any external tools?</a></p>\n\n<p>with a few given solutions that should work on almost every windows machine.</p>\n\n<p>As regards to the <em>shell.application</em> and WSH I preferred the <a href="https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/zipjs.bat" rel="nofollow noreferrer">jscript</a>\nas it allows a hybrid batch/jscript file (with .bat extension) that not require temp files.I\'ve put unzip and zip capabilities in one file plus a few more features.</p>\n'}]
['https://Stackoverflow.com/questions/30211', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1414/']