UNZIP anywhere in 200 bytes, embedded (XP and onwards)
Posted: 13 Nov 2024 20:33
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
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.