Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Vbscript to password protect a zip file

1,108 views
Skip to first unread message

TonyR

unread,
Feb 5, 2008, 5:55:53 PM2/5/08
to
I have a script which contains the following code to create a zip file and
copy several files into it using Windows Shell.

' Create an empty ZIP file
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
Set objTxt = objFSO.OpenTextFile( myZipFile, ForWriting, True )
objTxt.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
objTxt.Close
Set objApp = CreateObject( "Shell.Application" )
' Copy the files into the ZIP file
objApp.NameSpace( myZipFile ).CopyHere objApp.NameSpace(
myFolder ).Items
' Keep script waiting until compression is done
Do Until objApp.NameSpace( myZipFile ).Items.Count _
= objApp.NameSpace( myFolder ).Items.Count
WScript.Sleep 200
Loop

The script creates the zip file and does the copy just fine.
I need to put the zip file onto a CD for backup purposes but I'd like to
protect the contents from prying eyes.

Is there a way to password protect the zip file without using third party
software?

Thanks for any help you can offer.
Tony


Jeffery Hicks [MVP]

unread,
Feb 6, 2008, 9:23:01 AM2/6/08
to
Windows compressed files don't have a password option and you can't encrypt
a Windows compressed file either.

--
Jeffery Hicks MCSE, MCSA, MCT
Microsoft PowerShell MVP
http://www.scriptinganswers.com
http://www.powershellcommunity.org
http://jdhitsolutions.blogspot.com

Now Available: WSH and VBScript Core: TFM
Now Available: Windows PowerShell v1.0: TFM 2nd Ed.


"TonyR" <terpar@shaw[remove].ca> wrote in message
news:ZP5qj.45616$4w.19441@pd7urf2no...

Tom Lavedas

unread,
Feb 6, 2008, 1:44:30 PM2/6/08
to
On Feb 6, 9:23 am, "Jeffery Hicks [MVP]" <jhi...@sapien.com> wrote:

> "TonyR" <terpar@shaw[remove].ca> wrote in message
>
> news:ZP5qj.45616$4w.19441@pd7urf2no...
>
> > I have a script which contains the following code to create a zip file and
> > copy several files into it using Windows Shell.
>
> > ' Create an empty ZIP file

{snip}


>
> > Is there a way to password protect the zip file without using third party
> > software?
>
> > Thanks for any help you can offer.
> > Tony
>

> Windows compressed files don't have a password option and you can't encrypt
> a Windows compressed file either.
>
> --
> Jeffery Hicks MCSE, MCSA, MCT

> Microsoft PowerShell MVPhttp://www.scriptinganswers.comhttp://www.powershellcommunity.orghttp://jdhitsolutions.blogspot.com


>
> Now Available: WSH and VBScript Core: TFM
> Now Available: Windows PowerShell v1.0: TFM 2nd Ed.

Are you sure? I just checked my XP system and when I right-click in a
"Windows" compressed folder, there is an option to "Add a Password".
That would imply the Shell.Application can invoke that verb ("Add a
Pass&word") to do the job. I don't *know* it will work, since this
capability is supplied to MS by a third party, but it seems as if it
just might be possible. I don't have the time to pursue this.
Further, my quick check of the registry suggests that the verb might
NOT be supported in a way that would allow it to be accessed via the
Shell.Application interface.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Paul Randall

unread,
Feb 6, 2008, 3:33:42 PM2/6/08
to

"TonyR" <terpar@shaw[remove].ca> wrote in message
news:ZP5qj.45616$4w.19441@pd7urf2no...

Hi, Tony
I don't have any help with the password thing. I seem to recall that
in the days of PKZip, the password was rather weak. I think I once
downloaded and tested a password cracker that worked with the
passwords I tried. I could be wrong on this, though, and M$ may be
doing it better than PKWare did it.

A couple of comments on your script:
1) I got errors in the checking loop:


> Do Until objApp.NameSpace( myZipFile ).Items.Count _
> = objApp.NameSpace( myFolder ).Items.Count
> WScript.Sleep 200
> Loop

Wrapping these lines in
On Error Resume Next ... On Error GoTo 0
fixed that problem.

2) It was not obvious from the error messages I received that both
myZipFile and myFolder must be complete file paths; relative paths
don't seem to work.

Thanks for posting the script.

-Paul Randall


TonyR

unread,
Feb 7, 2008, 11:06:17 PM2/7/08
to
Hi Paul,
Thanks for the comments on my script. I've added the on error just like you
mentioned. And the myzipfile an myfolder are full paths otherwise it does
not work.

Tony


"Paul Randall" <paul...@cableone.net> wrote in message
news:%23MGHb%23PaIH...@TK2MSFTNGP03.phx.gbl...

sur...@gmail.com

unread,
Apr 4, 2008, 4:26:23 PM4/4/08
to
On Feb 8, 1:06 am, "TonyR" <terpar@shaw[remove].ca> wrote:
> Hi Paul,
> Thanks for the comments on my script. I've added the on error just like you
> mentioned. And the myzipfile an myfolder are full paths otherwise it does
> not work.
>
> Tony
>
> "Paul Randall" <paulr...@cableone.net> wrote in message
> > -Paul Randall- Hide quoted text -
>
> - Show quoted text -

Can you send my a full vbs file?
I´m dummy.
tks

0 new messages