Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# COM
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:\\");
   Shell32.Folder DestFlder = sc.NameSpace("c:\\test");
   Shell32.FolderItems items = SrcFlder.Items();
If 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!)
Posted 22-Jun-11 7:52am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Nope there is not. There is no way to pass this through any "legal" code.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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:
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:
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
        ' Set it foreground.
        ' Insert the password.
        ' Send ENTER.
    End If
End Sub
Which uses the method:
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
    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.
lukeer at 30-Aug-12 9:26am
aidin Tajadod at 28-Sep-12 19:04pm
thanks. but it is not what I was looking for! but good solution.
anyway my 5.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

You can unzip password protected zip files with ICSharpCode.SharpZipLib. It's free, and can be used in closed-source projects.
Kuthuparakkal at 30-Aug-12 11:42am
my 5+
aidin Tajadod at 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)

  Print Answers RSS
0 OriginalGriff 7,105
1 DamithSL 5,079
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,617
4 Kornfeld Eliyahu Peter 4,384

Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 30 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100