Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add a password to a zip file

Status
Not open for further replies.

Generalsndy

IS-IT--Management
Jan 22, 2016
7
0
0
PH
hello guys!
need help on how to add a password to the zip file created below. thanks
Code:
LOCAL m.cZipFileName
	m.cZipFileName=_targetFolder + DTOS(DATE())+" "+ STRTRAN(TIME(), ":", " ") + ".zip"
	
	STRTOFILE("PK"+CHR(5)+CHR(7-1)+REPLICATE(CHR(0),18),m.cZipFileName)
	oShell=CREATEOBJECT("shell.application")
	oShell.NameSpace(m.cZipFileName).copyhere(oShell.NameSpace(_SourceFolder))

 
STRTOFILE("PK"+CHR(5)+CHR(7-1)+REPLICATE(CHR(0),18),m.cZipFileName) is already creating a stub of an unencrypted empty zip file and there is encryption foreseen in this stub.

And I just tried: If you create an encrypted zip file with WinZIP compatible AES encryption Windows can't handle it anymore, that means the copyehere() method doesn't work, you get OLE error 0x80004005: Unspecified error, when trying to add more files to such an encrypted zip file.

Just to emphasize: If you only do your code up to STRTOFILE you already have created an unencrpyted empty zip file, you can open it in Windows or Winzip and see no content inside it. An encrypted zip file also is just a small number of bytes you could create in the same manner, but the copyhere method doesn't work with such a file.

You need to use a tool, that's capable of creating encrypted zip files, eg 7Zip.exe with command line parameters.

Bye, Olaf.






 
As Olaf says, unfortunately the shell's built-in zip capability does not support zip encryption
 
You can use command-line parameters with WinZip:

Code:
winzip32 -s"My Password" "c:\data\My Compressed File.zip"

Source and further information:
You can run the above via ShellExecute:

Code:
DECLARE INTEGER ShellExecute IN shell32.dll ; 
  INTEGER hndWin, ; 
  STRING cAction, ; 
  STRING cFileName, ; 
  STRING cParams, ;  
  STRING cDir, ; 
  INTEGER nShowWin

lcParams = [-s"My Password" "c:\data\My Compressed File.zip" ]
ShellExecute(0, "open", "c:\Program Files\Winzip\Winzip32.Exe", lcParams, "", 1)

I haven't tested the above, but it should give you the general idea.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
WinZip isn't free AFAIK. That doesn't mean it's a bad choice, of course. But since there are many compatible data compression suites, I favor 7Zip. Others favor Rar. There are much stronger compression tools, but not widely usable. If it's worth it, you may try Chilkats ActiveX Zip class:
Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top