Page 1 of 1

UNZIP anywhere in 200 bytes, embedded (XP and onwards)

Posted: 13 Nov 2024 20:33
by mydigitalbutter

ZIP self extractors are anywhere from 20kb to 300kb, so I wanted something a bit more portable.
There are two versions of the script.


Version one, unzips into the current directory

Code: Select all

Set z=CreateObject("Shell.Application")
Set x=CreateObject("Scripting.FileSystemObject")
v=x.GetFile(WScript.Arguments(0))
Set w=z.NameSpace(v).Items()
Set v=z.NameSpace(x.GetAbsolutePathName(""))
v.CopyHere w

Version two, unzips into the script directory

Code: Select all

Set z=CreateObject("Shell.Application")
Set x=CreateObject("Scripting.FileSystemObject")
v=x.GetFile(WScript.Arguments(0))
Set w=z.NameSpace(v).Items()
Set v=z.NameSpace(Left(v,InStrRev(v,"\")-1))
v.CopyHere w

The current directory and script directory are usually one and the same, but you may want to put this in a common path like system32 and call from anywhere.

Usage:
unzip file.zip
unzip.vbs file.zip
unzip.vbs path\to\file.zip

Relative paths are accepted.

Embedded example

Code: Select all

@echo off

>unzip.vbs (
echo Set z=CreateObject("Shell.Application"^)
echo Set x=CreateObject("Scripting.FileSystemObject"^)
echo v=x.GetFile(WScript.Arguments(0^)^)
echo Set w=z.NameSpace(v^).Items(^)
echo Set v=z.NameSpace(x.GetAbsolutePathName(""^)^)
echo v.CopyHere w)

unzip shareware.zip
Notice you can call unzip with/without the extension but be aware of name collisions, some extensions take precedence over vbs, ex;
unzip shareware.zip will work unless a com/exe/bat OR cmd exists by the same name (don't call unzip from unzip.cmd)
unzip.vbs shareware.zip always works.

Re: UNZIP anywhere in 200 bytes, embedded (XP and onwards)

Posted: 18 Nov 2024 08:43
by npocmaka_
You might be interested in this: https://github.com/npocmaka/batch.scrip ... /zipjs.bat - a script that uses windows capabilities to zip/unzip files and I've wrote long ago.