使用shell32.dll解压缩受密码保护的zip文件 [英] decompress password protected zip files using shell32.dll
问题描述
大家好,
我想用shell32.dll解压缩zip文件(我试图不使用第三方组件).
一切都很好.但是我找不到解压缩受密码保护的zip文件的方法!
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);
如果test1.zip受密码保护,它将显示一个对话框窗口,用于输入密码!
有什么办法可以通过密码传递密码? (我想在Windows服务中使用此代码!)
谢谢.
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.
推荐答案
没有.无法通过任何合法"代码传递此信息.
Nope there is not. There is no way to pass this through any "legal" code.
嗨.
我只是遇到了同样的问题,自己找到了解决方法.
也许知道您或其他任何人仍然可能感兴趣.
所以,我所做的基本上是:
添加具有API函数的模块以将找到的窗口设置在前景中:
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:
Module mdlWinAPI
Public Declare Ansi Function SetForegroundWindow Lib "user32.dll" _
Alias "SetForegroundWindow" (ByVal hwnd As IntPtr) As Boolean
End Module
然后,我在表单中添加了一个计时器,设置为1/4秒-只是看是否有一个窗口具有该特定的标题("Password Richiesta").您必须将该字符串更改为您的语言本地化,即:"Required Password".
计时器内的代码是:
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
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:
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
我其余的代码没有做很多事情:显示zip文件中的文件,然后将它们解压缩到指定的文件夹中.
希望有人会发现此解决方法有帮助.
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.
您可以使用ICSharpCode.SharpZipLib解压缩受密码保护的zip文件.它是免费的,可以在封闭源代码项目中使用.
You can unzip password protected zip files with ICSharpCode.SharpZipLib. It''s free, and can be used in closed-source projects.
这篇关于使用shell32.dll解压缩受密码保护的zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!