Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I want to decompress zip files with shell32.dll ( I am trying not to use third party components).

Every thing is working fine. But I could not find a way to decompress password protected zip files!!

Shell32.ShellClass sc = new Shell32.ShellClass();
Shell32.Folder SrcFlder = sc.NameSpace("c:\\test1.zip");
Shell32.Folder DestFlder = sc.NameSpace("c:\\test");
Shell32.FolderItems items = SrcFlder.Items();
DestFlder.CopyHere(items,20);


If test1.zip is password protected, it will show a dialog window to enter the password!
Is there any way to pass the password through the code? ( I want to use this code in a windows service!)

Thanks.
Posted

Nope there is not. There is no way to pass this through any "legal" code.
 
Share this answer
 
v2
Hi.

I just had the same problem and found a workaround bymyself.
Maybe know you or anyone else could be still interested in.

So,what I did was basically:

Add a module with an API function to setthe found window in foreground:

VB
Module mdlWinAPI
    Public Declare Ansi Function SetForegroundWindow Lib "user32.dll" _
     Alias "SetForegroundWindow" (ByVal hwnd As IntPtr) As Boolean
End Module


Then, I added a timer to my form, set to 1/4 second - just to look if there's a Window wich has that specific Caption ("Password Richiesta"). You must change that string to your language localization, i.e.: "Required Password".

The code inside the timer is:

VB
Private Sub tmrCheck_Tick(ByVal sender As Object, ByVal e As EventArgs) _
 Handles tmrCheck.Tick
    ' Specify part of the window title you want.
    ' Get its window handle.
    Dim hwnd As IntPtr = Window_FindPartialTitle("Password Richiesta")
    If hwnd <> IntPtr.Zero Then
        tmrCheck.Stop()
        ' Set it foreground.
        SetForegroundWindow(hwnd)
        ' Insert the password.
        SendKeys.Send(Pwd_VideoPress)
        ' Send ENTER.
        SendKeys.Send("{ENTER}")
    End If
End Sub


Which uses the method:

VB
Private Function Window_FindPartialTitle(ByVal partialTitle As String) _
 As IntPtr
    ' Find handle by partial window title
    For Each p As Process In Process.GetProcesses()
        If p.MainWindowTitle.IndexOf(partialTitle, 0, StringComparison.CurrentCultureIgnoreCase) > -1 Then
            Return p.MainWindowHandle
        End If
    Next
    Return IntPtr.Zero
End Function


The rest of my code doesn't do much: Shows the files inside the zip and Unzips them to a specified folder.

Hope that someone will find this workaround helpful.
 
Share this answer
 
Comments
lukeer 30-Aug-12 9:26am    
Nice.
aidin Tajadod 28-Sep-12 19:04pm    
thanks. but it is not what I was looking for! but good solution.
anyway my 5.
You can unzip password protected zip files with ICSharpCode.SharpZipLib. It's free, and can be used in closed-source projects.
 
Share this answer
 
Comments
Kuthuparakkal 30-Aug-12 11:42am    
my 5+
aidin Tajadod 28-Sep-12 19:02pm    
my 5, Thanks.
I ended up using ICSharpcode as you recomended!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900