locked
manipulating zipfldr.dll to create a Compressed folder RRS feed

  • Question

  • Hi, I'm looking at creating a small app that needs to compress files and folders.  Obviously, i'll need this to use Windows' built-in zip support (because otherwise my app would have to use 3rd party software that I'd need to distribute along with it)

    I know that the command rundll32.exe zipfldr.dll,RouteTheCall %filename% opens a zip file in explorer, but I need the command to create a zip file.

    Can anyone help?

    Andy

    Saturday, September 2, 2006 9:49 PM

All replies

  • If you have the resource kit, you can run the compress command from the command prompt.
    Monday, September 25, 2006 8:26 PM
  • If you use the above method, you have to make it a .cab file.

    I would like to know if there is a command to get a .zip file.

    Wednesday, September 27, 2006 8:10 PM
  • I tried the cab creation tool ( makecab.exe ). Unfortunately, it gives a poor compression in compare to "Compressed Folder" option (it takes twice as much space for huge file). What I am surprised is at why people give tangent replies (like use third party tool etc.) when they can't address the real problem. To me it looks like msdn forum and other -similar- forums almost always try to shield (protect) the third party zip utilities.

    Keywords:: Rundll32.exe, Zipfldr.dll, Dunzip32.dll, Dzip32.dll

    Thursday, October 5, 2006 11:41 PM
  • I dont know if this is an old thread or not, but I would like to have the same question answered as the first guy. I want to know how to send files to a zipped folder via batch. I know it has something to do with "rundll32.exe zipfldr.dll,<something goes here> '*.zip'" But other than that I can't figure it out. Any ideas anyone?

    • Proposed as answer by FrankRLiga Monday, October 26, 2009 8:07 PM
    Thursday, July 26, 2007 4:47 PM
  • Has anyone ever responded with information that might unfold the mystery? I am looking for the same solution because Microsoft claims to have the "Build In" feature of the Compressed Folders. I see it works in the interface but they seem unwilling to allow anyone to use it within a block of code.

     

    I am working different projects for DOD and private sector and am looking to build the tool as a standard component of reusable code to archive data files for projects. Is there a definitive text or help file that describes the parameters / calling conventions of the compressed folders capabilities built into Windows XP Pro?

     

    Thanks,

    Steve

    Friday, August 3, 2007 6:28 PM
  • No, this isn't possible without some third party program. The DLL only has the standard entry points plus RouteTheCall (which will open a zip file as a Compressed Folder) and RegisterSendto (which remakes the Sendto item should you accidentally delete it).

     

    Now, if you're hell bent on doing this I think you can with something like CMCDDE to pass the DDE execution to the DLL at runtime.

     

     

     

    Friday, November 9, 2007 4:11 PM
  • Friday, November 9, 2007 10:15 PM
  • I found this sniplet of code in the web on how to use C# using COM library. But it seems to be the same as the VB sample.

    Anybody here knows how to do this using C++?
    __________________________________________________
    http://www.autohotkey.com/forum/topic15135.html
    __________________________________________________
    //Create an empty zip file
    byte[] emptyzip = new byte[]{80,75,5,6,0,0,0,0,0,
                      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

    FileStream fs = File.Create(args[1]);
    fs.Write(emptyzip, 0, emptyzip.Length);
    fs.Flush();
    fs.Close();
    fs = null;

    //Copy a folder and its contents into the newly created zip file
    Shell32.ShellClass sc = new Shell32.ShellClass();
    Shell32.Folder SrcFlder = sc.NameSpace(args[0]);
    Shell32.Folder DestFlder = sc.NameSpace(args[1]);
    Shell32.FolderItems items = SrcFlder.Items();
    DestFlder.CopyHere(items, 20);
    __________________________________________________
    Tuesday, November 20, 2007 8:35 PM
  •  

    I tried doing it in C using COM, but I keep running into a problem when using it from a console program: The program exits before the zipping can be completed, and this correction does not work.

    It seems that zipfldr.dll does not call SHGetInstanceExplorer despite creating worker threads. This may be a bug in zipfldr.dll...

    Tuesday, August 5, 2008 10:44 AM
  • Sunday, August 31, 2008 8:48 AM
  • This is a code snippet to UNZIP a .zip file to a folder.

    You can use the reverse thing for makking .zip files.

     

    bool UnZipFolder(LPCTSTR zipFile,LPCTSTR destination)
       {

        DWORD     strlen = 0;
        HRESULT     hResult;
        IShellDispatch *pISD;
        Folder  *pToFolder = NULL;
        Folder  *pFromFolder = NULL;
        FolderItems *pFolderItems = NULL;
        FolderItem *pItem = NULL;
        
        VARIANT   vDir, vFile, vOpt;
        BSTR  strptr1, strptr2;
        CoInitialize(NULL);
        
        bool bReturn = false;
        
        hResult = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER,
         IID_IShellDispatch, (void **)&pISD);
        
        if(FAILED(hResult))
        {
         return bReturn;
        }
        
        VariantInit(&vOpt);
        vOpt.vt = VT_I4;
        vOpt.lVal = 16+4;     // Do not display a progress dialog box ~ This will not work properly!
        
        
        CString strZipFile(zipFile);
        CString strDestination(destination);
        strptr1 = strZipFile.AllocSysString();
        strptr2 = strDestination.AllocSysString();
        
        VariantInit(&vFile);
        vFile.vt = VT_BSTR;
        vFile.bstrVal = strptr1;
        hResult = pISD->NameSpace(vFile, &pFromFolder);  
        
        VariantInit(&vDir);
        vDir.vt = VT_BSTR;
        vDir.bstrVal = strptr2;
        
        hResult = pISD->NameSpace(vDir, &pToFolder);
        
        if(S_OK == hResult)
        {
         hResult = pFromFolder->Items(&pFolderItems);
         if(SUCCEEDED(hResult))
         {
          long lCount = 0;
          pFolderItems->get_Count(&lCount);
          IDispatch* pDispatch = NULL;
          pFolderItems->QueryInterface(IID_IDispatch,(void**)&pDispatch);
          VARIANT vtDispatch;
          VariantInit(&vtDispatch);
          vtDispatch.vt = VT_DISPATCH;
          vtDispatch.pdispVal = pDispatch;
               
          //cout << "Extracting files ...\n";
          hResult = pToFolder->CopyHere(vtDispatch,vOpt);
          if(hResult != S_OK) return false;

     

          //Cross check and wait until all files are zipped!
          FolderItems* pToFolderItems;
          hResult = pToFolder->Items(&pToFolderItems);
          
          if(S_OK == hResult)
          {
           long lCount2 = 0;   
                  
           hResult = pToFolderItems->get_Count(&lCount2);
           if(S_OK != hResult)
           {
            pFolderItems->Release();
            pToFolderItems->Release();
            SysFreeString(strptr1);
            SysFreeString(strptr2);
            pISD->Release();
            CoUninitialize();
            return false;
           }
           //Use this code in a loop if you want to cross-check the items unzipped.
           /*if(lCount2 != lCount)
           {
            pFolderItems->Release();
            pToFolderItems->Release();
            SysFreeString(strptr1);
            SysFreeString(strptr2);
            pISD->Release();
            CoUninitialize();
            return false;
           }*/
           
           bReturn = true;
          }      
          
          pFolderItems->Release();
          pToFolderItems->Release();
         }
         
         pToFolder->Release();
         pFromFolder->Release();
        }
        
        //cout << "Over!\n";
        SysFreeString(strptr1);
        SysFreeString(strptr2);
        pISD->Release();
        
        CoUninitialize();
        return bReturn;
       }

     

    Monday, October 6, 2008 10:52 AM
  • As you've probably realized by now, Windows provides no direct way to use zipfldr.dll for zipping or unzipping.

    So I quickly wrote a small exe around SharpZipLib

    You can zip and unzip whole folders from the command line with it; no 3rd party tools required.

    But I haven't coded it to accept individual file(s), only an entire folder.

     

    You can pick it up from here - http://www11.brinkster.com/shaurya/Downloads.htm#ZipfldrAlt
    If you can't get it there or want the source code to enhance or something, mail me at shaurya at gmail dot com.

     

    But you'll need this exe to zip or unzip at the command line.

    It doesn't solve the problem of using an in-built feature.

     

    But that's the only dependency.

    I've used ILMerge so the whole thing is one exe file, about 200kb.

    In my case, I package it along with the zip file in my setup file.
    Friday, November 28, 2008 6:59 AM
  • If you are using VB.Net you can use the following code as shown below

    NOTES :
    1. Copy it EXACTLY as shown, make sure it works, then modify it. For example, "ToString" shouldn't be required, but is..
    2. This has only been tested on Windows Vista and Windows Server 2003
    It should work on any version of Windows that pretends zip files are compressed folders
    3. This works by creating an empty zip file. Then it copies the file you want to compress into the zip file. Windows will see that you are copying into a zip file not a folder, and compress it on the way in.

    -------------------------------------------------------------

        Private Sub zipFile(ByVal filename As String, ByVal zipfilename As String)
            Dim strZIPHeader As String

            strZIPHeader = Chr(80) & Chr(75) & Chr(5) & Chr(6) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0)
            Dim fso = CreateObject("Scripting.FileSystemObject")
            Dim tf = fso.CreateTextFile(zipfilename)
            tf.Write(strZIPHeader)
            tf.Close()

            With CreateObject("Shell.Application")
                .NameSpace(zipfilename.ToString).CopyHere(filename.ToString)
            End With
            MessageBox.Show("All done!")
        End Sub

    Monday, March 2, 2009 12:56 PM
  • Sorry to high jack this, but can someone please tell me how to re-associate the compressed zip folder functionality to the .zip extension? I am on vista and used to be able to use the built in functionality to open .zip files. I accidentally associated the extension to another software (winrar) by "open with" and "always open with this program" selected. Does anyone know how to re-associate the built in compressed zip to the .zip files. Thanks a million.
    Friday, April 2, 2010 9:25 AM
  • you can try to right-click on one of zip file, click Open with... menu item, click Windows Resource Explorer to open it. 
    Saturday, October 13, 2018 1:56 PM