网上找到的unzip.dll在vb中调用代码有个函数是这样的:
Public Function UZDLLPass(ByRef p As UNZIPCBCh, _
ByVal n As Long, ByRef m As UNZIPCBCh, _
ByRef Name As UNZIPCBCh) As Integer
这时候在9x、2k、xp下都没问题,但是在vista下解压带密码的zip文件时,无论输入什么,都反馈err82(密码错误)
改为:
Public Function UZDLLPass(ByRef p As UNZIPCBCh, _
ByVal n As Long, ByRef m As UNZIPCBCh, _
ByRef Name As UNZIPCBCh) As Long
错误即可修复
Private Sub Command1_Click()
SourceFile = "c:\mon.rar": TargetPath = "c:\test": Passw = "123"
If Dir(SourceFile) = "" Then MsgBox "解压文件不存在": Exit Sub
Call CloseExe("rar.exe") '检查是否有Rar.exe在运行,有的话就关掉
aa = "rar x -y -p" & Passw & " -o+ " & SourceFile & " " & TargetPath
Call Shell(aa, vbHide)
starttm = Timer
Do
DoEvents
If Isrunexe("rar.exe") = False Then Exit Do
Loop Until Timer > starttm + 5
If Timer > starttm + 10 Then
MsgBox "密码错误或其它原因解压失败"
Call CloseExe("rar.exe") '关掉Rar.exe
Else
MsgBox "解压成功"
End If
End Sub
Public Function Isrunexe(Exenm As String) As Boolean
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcesslist = objWMIService.ExecQuery("Select * from Win32_Process Where Name = '" & Exenm & "'")
Isrunexe = IIf(colProcesslist.Count > 0, True, False)
Set objWMIService = Nothing
Set colProcesslist = Nothing
End Function
Public Sub CloseExe(Exenm As String)
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcesslist = objWMIService.ExecQuery("Select * from Win32_Process Where Name = '" & Exenm & "'")
If colProcesslist.Count > 0 Then
For Each objProcess In colProcesslist
If InStr(UCase(objProcess.ExecutablePath), UCase(Exenm)) > 0 Then objProcess.Terminate
Next
End If
Set objWMIService = Nothing
Set colProcesslist = Nothing
End Sub
Directories 文件夹选项
-r Recurse Directories 含文件夹內內容。
-p Save Extra Directory Info 储存其他的文件夹信息。
method 決定压缩的方法选项
-ex eXtra 最大 (最慢)
-en Normal 一般 (默认值)
-ef Fast 快速
-es Super fast 最快速
-e0 no compression 不压缩
其他选项
-s 设定密码 密码必须使用双引号括起来。
例如:-s "Secret Password",不过要注意大小写是不同的!
-hs 包含符合条件的隐藏及系统文件。