Windows XP – How to Zip Files in Command Line Without Additional Tools

command linewindows xpzip

After prowling google, and checking an old thread in ServerFault, I thought I would try here. Without any additional downloads, on a fresh install of XP SP3, how can I run a script to extract AND zip a file into a .zip?

People have tried saying to use third party utilities, but that requires downloading a program as well, and making sure they're in the same location all the time. I don't want to download the Microsoft Resource Kit just for this one chunk of functionality on multiple computers

Best Answer

You can do this with VBScript. This question has been asked on Stack Overflow, and this answer comes from Jay:

Dim fso, winShell, MyTarget, MySource, file
Set fso = CreateObject("Scripting.FileSystemObject")
Set winShell = createObject("shell.application")


MyTarget = Wscript.Arguments.Item(0)
MySource = Wscript.Arguments.Item(1)

Wscript.Echo "Adding " & MySource & " to " & MyTarget

'create a new clean zip archive
Set file = fso.CreateTextFile(MyTarget, True)
file.write("PK" & chr(5) & chr(6) & string(18,chr(0)))
file.close

winShell.NameSpace(MyTarget).CopyHere winShell.NameSpace(MySource).Items

do until winShell.namespace(MyTarget).items.count = winShell.namespace(MySource).items.count
    wscript.sleep 1000 
loop

Set winShell = Nothing
Set fso = Nothing
Related Question