Click here to Skip to main content
12,698,939 members (22,962 online)
Rate this:
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 30-Aug-12 9:26am
aidin Tajadod 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 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 30 Aug 2012
Copyright © CodeProject, 1999-2017
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