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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A Better UnZip

Status
Not open for further replies.

bont

Programmer
Sep 7, 2000
200
0
0
US
I am trying to build into a VB app the ability to unzip from a provided ZIP file. I have been able to do this with InfoZip. At the moment, I can't figure out how to unzip using a password? If anyone has an example of code to simply unzip all the files from a zip file that have the same password, please post it. It doesn't appear to be too simple.

Simple it the key word. I guess my question is, what is the best way to unzip a file from VB6. I am dealing with Win2000 and XP, and it is my understanding that these OS already have the capability of unzipping. Is there a way to use their method of unziping? This would not require me to distribute the INfoZip DLL.
 
WinZip has great command line support and isn't to hard to use (if you have a licenced version) all you need to do is download it.

I have been looking reciently at 7-Zip

freeware.. Not bad. Has builtin command line support and supports many compression algorithims. .zip,.lzh,.rar as well as it's own Z format (which is much better than .zip at compression).


7z x archive.zip

would [blue]x[/blue]Tract all the files in archive.zip to the current directory..

Web site:
Clean and easy


HTH


Rob
 
I guess this would be OK, but command line is not really all that professional. API is what I am currently using with InfoZip. The only problem I have is getting the password to work, which I am sure is a matter of not having an example of it.

Also, using something like WinZip and 7z would require the user to have said product installed. With the InfoZip I just drop a DLL in the sys directory and then can reference, without a secondary install.

I really don't understand why there isn't a way to do this via some sort of already pre-installed windows DLL, as the functionality is built in to Windows (extraction that is).
 
Ok if you need to run it from your application just "wrap" the command line argument in a Shell "cmd" then it can do it's magic.. WinZip's tool supports commandline password support (I wrote a backup app that uses it to zip with password and unzip with password) all via Command Line behind the scenes..

API would be nice, but often you need more control and you should find all the capiblilbites you need without too much work.

i.e. 7z x archive.zip -psecret
extracts the files in archive.zip using a password of secret to open it..

Or in VB syntax

Code:
shell "cmd /C '7z x archive.zip -psecret'"

HTH


Rob
 
Ok all, I have but a few comments to add.

1. The question was raised about using an already pre-defined unzip capability (the one that comes with Windows) because it is silly to require the user to either install a new DLL (as I am doing now), or install an entire application (as Rob's suggestion does).

2. Rob's Suggestion is dangerous. When you call the shell command it does not guarentee that the VB will wait for the calls completion. I would never recommend this, when something such as this could take time to do. Especially if your extracted files are needed for other things.

F.Y.I. The InfoZip DLL has as problem as the password ability is vague, I can't figure it out, nor can I find examples

??? Both of the Microsoft install utilities allow for extraction. Is there a way to envoke this same extraction?
 
bont,

Your reservations with NoCoolHandle's method can be overcome if you use a Shell and then Wait technique, like;

'ShellAndWait stuff
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function WaitForInputIdle Lib "user32" (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long
Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Const INFINITE = &HFFFF, SYNCHRONIZE = &H100000

Sub ShellAndWait(sAppPath$, Optional iWindowStyle As VbAppWinStyle = vbMinimizedFocus, Optional lmsTimeOut As Long = INFINITE)

'pass your program path/ name and and arguments in sAppPath$
'ref Compuserve BasLan #732415 from Tom Esh

Dim lPid As Long, hProc As Long, lTimeout As Long

lPid = Shell(sAppPath, iWindowStyle)
hProc = OpenProcess(SYNCHRONIZE, 0&, lPid)
If hProc <> 0& Then
WaitForInputIdle hProc, INFINITE
WaitForSingleObject hProc, lmsTimeOut
CloseHandle hProc
End If

End Sub

Thus your program can be made to wait until the Zip is done.
My preference like NoCool's is to use the InfoZip Zip.exe and UnZip.exe files called from Shells. Tried the .dll route but it did'nt do it for me, there seemed to be a lot of similar .dlls available and some certainly seemed incompatible with others.

regards Hugh,
 
bont,

Your first point.
Yes it is pretty silly that Windows ME and later has Zip and UnZip capability but I have never been able to find a way of accessing it either. I've asked the same question on several forums and no-one has come back with a thing.

Hugh

 
Have you looked at Bigspeed zip?

FREE application with a command line option. No nag screens, and can integrate into Win Explorer just as WinZip.

Both DLL and OCX options are also available for a price.

for the application
for the DLL
for the OCX

Been using all 3 for a couple of years without issue.

Tony McGuire
 
Bont

. Rob's Suggestion is dangerous. When you call the shell command it does not guarentee that the VB will wait for the calls completion. I would never recommend this, when something such as this could take time to do. Especially if your extracted files are needed for other things.

Not so dangerous if...

you use the findwindow api call to see if it is still executing... and unitl findwindow returns a 0 keep waiting... Not too hard to getaround. (assuming you need sync commands rather than async...)
 
All,

Please don't post to this thread unless a solution exists that would not involve:

- purchasing
- Installing anything (DLL or other app)

The best FREE solution has been found, we are just interested in a solution, which might allow use to use the already present unzip features of the windows OS (ME -> Latest Editions).
 
Hi All,
Think i might be a bit late for posting a reply ..
But i have tried this one and its real kewl ....

Maybe it might be worth a look ... (for some future use maybe ..)


cheers !!! ;-)
Killerkoolkris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top