Checking encryption on zip file

  • Hi guys,

    I'm currently trying to write something that *tests* to see if a zip file is password protected. Let me be clear at this point that I'm not attempting to bypass anything, I'm testing that the user has password protected the file before it is sent via email.

    Everything I try at the moment throws up a prompt asking for the password which not only pauses code execution, but isn't going to be acceptable as the code is fired every time an email is sent...

    I've tried using the Shell App/Namespace method with same results, trying not to rely on using a 7-zip approach because not all users will have it installed.

    Here's what I've got so far:

    If anyone has any suggestions or pointers it would be greatly appreciated :)

    Any questions let me know.

  • Re: Checking encryption on zip file


    I've got a (kind of) solution:

    I've dropped a copy of the 7z.exe file on a shared drive, along with a batch file.

    My UDF calls the batch file which returns true or false by testing the encryption using the 7z.exe command line switches.

    Private Function SecureZipFile(zipFile As String) As Boolean
    SecureZipFile = Split(CreateObject("WScript.Shell").Exec("CMD /C \\*****\***\RES\ziptest2.bat """ & zipFile & """").StdOut.ReadAll, vbCrLf)(0)
    End Function

    Annoyingly, this seems to only work on some computers, which are all identical builds and I cannot fathom for the life of me why it works on some and not on others.

    If anyone is interested, this is the .bat file contents.

    echo off

    echo garbage | \\*******\****\RES\7z.exe t -y %1 >nul 2>nul

    if errorlevel 2 (
    echo True
    exit /b %errorlevel%

    if errorlevel 0 (
    echo False
    exit /b %errorlevel%

    At this point, I'm pretty sure the issue is no longer VBA related and so if an admin/mod agrees then absolutely feel free to close this thread. Just curious to see if anyone has a purely VBA solution.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!