代码之家  ›  专栏  ›  技术社区  ›  Eugen-Andrei Coliban HARI PRASAD GANGI

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

  •  1
  • Eugen-Andrei Coliban HARI PRASAD GANGI  · 技术社区  · 6 年前

    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);
    

    1 回复  |  直到 6 年前
        1
  •  2
  •   SangHun    6 年前

    使用上一个示例,您将无法使用密码从存档中提取文件,我建议您使用7zip或类似的工具。下面是一个使用7zip查看非归档流程的示例:

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