使用密码从 ZIP 存档中提取文件

Extract files from a ZIP archive with password

我正在使用 JScript 编写一个脚本,该脚本将从具有密码的 ZIP 存档中提取 filez。首先,我在 Whosebug 上的另一个线程上找到了一个 VBS 中的脚本,它解决了这个问题,这里是:

WScript.echo("Instantiating a ZipFile object...")

Dim zip 
Set zip = CreateObject("Ionic.Zip.ZipFile")

WScript.echo("Initialize (Read)...")
zip.Initialize("C:\Temp\ZipFile-created-from-VBScript.zip")

WScript.echo("setting the password for extraction...")
zip.Password = "This is the Password."

' set the default action for extracting an existing file
' 0 = throw exception
' 1 = overwrite silently
' 2 = don't overwrite (silently)
' 3 = invoke the ExtractProgress event

zip.ExtractExistingFile = 1

WScript.echo("extracting all files...")
Call zip.ExtractAll("extract")

WScript.echo("Disposing...")
zip.Dispose()

WScript.echo("Done.")

我试图用 JScript 重写这个 scipt,但是当我执行它时,它不断返回与 Ionic.Zip.ZipFile 库相关的错误,所以我有了另一个解决方案,现在在 JScript 中:

objShell = new ActiveXObject("Shell.Application");

FilesInZip = objShell.NameSpace(zipFile).Items();
objShell.NameSpace(path).copyHere(FilesInZip, 4);

但是,此脚本只是从存档中提取文件,有人可以查看此代码并帮助我,或者,也许可以为我的问题提供另一种解决方案吗?

使用上一个示例,您将无法使用密码从存档中提取文件,我建议您使用 7zip 或类似软件。这是使用 7zip 解压缩过程的示例:

function ExtractFile(FileName, Password) {
    executableCommand = "x " + FileName + " -p" + Password;
    objShell.ShellExecute("7z.exe", executableCommand, /*Path to 7Zip*/, "open", 0);
}