System and Security: Creating archives on MS Windows.
Archives are compressed files and folders, the most commonly encountered on Windows are .zip archives (on Unix systems,
.gz and .tar or .tar.gz, a combination of both, are those mostly used). But there are lots others, as for example .rar or the Windows .cab files.
Whereas on Windows XP you had to use external programs such as WinZip or WinRar to open archives, the file explorer of modern Windows versions allows
to open some of them, in particular .zip files. There is a packer/unpacker utility, that I personnaly would call the "best archieving program ever" (a
real "must have" on every computer: 7-Zip is a completely free multi-platform utility, that may be
used to open any common archive, including .tar, .gz, .cab. .iso images, Mac OS .dng files and Debian Linux .deb files. 7-zip also allows to easily
create archives, using either the .zip or its own .7z format.
Some reasons why to create archives.
- Files contained in an archive are compressed, i.e. reduced in size. Thus, a first reason is simply to make free space on your harddisk by doing files, that you don't actually need, but that you want to keep (as for example the logfiles of a webserver) into archives.
- E-mail providers set a size limit of the attachements, that you make to your mails, thus compressing the files allows to send lots larger files.
- If you run a website with files to download, using archives for these files has all advantages: usage of less space on your site, faster download, less load on the webserver.
- And finaly: Using archives is a simple way to protect personal data. archives may be password-protected, thus your data is secure from unwanted access by other people.
Creating archives using 7-Zip.
When installing 7-Zip with all default settings, the setup program adds several 7-Zip related entries to the file explorer context
menu. This allows you to archive a file or an entire folder "on the fly": just right-click the file and choose 7-Zip > Add to
[filename].zip (or: 7-Zip > Add to [filename].7z). This creates an archive with the same name as the file/folder you clicked, using default options.
You may also include several files in the archive by this way: select the files by holding down the CTRL key when you click them (with the left mouse
button), then click one of the highlighted (= selected) files with the right button and make your 7-Zip choice. It's this way, that I create the .zip
files of my Lazarus/FreePascal executables and sources to be downloaded from my website.
The procedure described above allows to create a new archive of one or more files or folders. But, what to do if you want to add files to an existing
archive? Just proceed the same way, but this time choosing 7-Zip > Add to archive... after you right-clicked the files. The
7-Zip options window opens and here you can browse to the .zip or .7z archive that you want to add the files to. You may also choose here lots of
specific settings, thus for example the archive type (.zip or .7z), the compression level or the password, if you want to encrypt the archive. Have
a look at the 7-Zip help content if you want to have more information. I myself use this procedure each time when I have finished with the development
of a new Lazarus/FreePascal program to add the new executable or source files (as folder content) to #FreePascal.zip resp. #FreePascal_src.zip, the files,
that I offer as "download all at once" on my website.
You should associate all archive types with 7-Zip (on Windows 10, file associations are set in the "Default applications"
section of "Settings" (in the Start menu). Otherwise, right-click the file, choose "Open with..." and browse to the 7-Zip executable (located in
C:\Program Files\7-Zip if you installed the 64bit version) and there select it (filename = 7zFM.exe). Opening an archive in 7-Zip
allows you to individually access the files it contains. You may extract one or several of them, delete some of them, that you don't want to be
there, or open a file in an external program, for example open a ReadMe.txt file in a text editor to directly view its content.
Notice the compression of the AlarmClock folder: from 3.5MB original size to 1.5MB in the .zip archive!
Creating self-extracting .cab files.
Cabinet files for Microsoft Windows systems (.cab files) are in fact executables, containing not only the archived files,
but also program code to automatically extract these files when the user double-clicks them as well as eventually the code to automatically launch an
installation program if the files in the .cab constitute an application themselves.
MS Windows includes lots of programs, that do not appear in the Start menu; most of them are located in the C:\Windows\System32 folder (mentionned by the
way: one of these programs, called regedit allows to edit the system registry). To launch these programs you have to use the Run
command. To do so, right-click the Start menu icon, and select "Run". A small box opens and herein you may type the name of the program you want
to execute (e.g. regedit, to run the registry editor).
There is a utility to create .cab files included with Windows (I suppose in all its somewhat recent, perhaps even its old versions). To execute it, in order to create a self-extracting archive, open the Run propmpt and type iexpress.
The creation of the .cab archive is wizard driven; each screen asking a specific question about the features it shall have. In the first screens, you
can choose if you want to create a new archive (or open an existing one) and, when you create a new, what it's purpose is: extract files only (or extract
files and run an installation program or create compressed files only)
The following screens (no screenshots) ask for a package name, to enter or not a prompt asking the user if she really wants to install the package (this, because .cab archives typically contain system files and other Windows components), to display or not a license agreement.
IExpress then asks to add the files to be included in the archive: pushing the "Add" button will display an "File Open dialog", where you may select
your files (use the CTRL or the SHIFT key to select multiple files). The IExpress utility works with files only, not with folders; this means that it
is not possible to archive a folder structure that is recreated with file extraction (i you choose to create a .cab with installation program, the wizard
will, of course, also ask information about this).
The wizard continues (no screenshots) to ask how the installation window has to be shown (selcting "default" is preselected as recommended), if or not
a message has to be displayed when the installation is complete. It then asks for the path where to create the new archive. Note that the extension of
the archive created is '.exe' and not .cab; as I said above these files are executables. To show it actually is a cabinet file, you may want to use the
"double extension" .cab.exe.
The wizard the asks if you want to save the selections you made (so you can use them later again) and then asks to create the package. The first screenshot
below shows the .cab creation in Command Prompt (iexpress is a command line program); the second one shows the final message (with statistics about the .cab)
created) of the IExpress utility.
To extract the files from a .cab.exe file, just double-click it. A dialog box opens, asking where to put the extracted files. Browse to the destination
folder you want ... the program does the rest. With the limitation, not being able to recreate folder structures. To do so, a third party application is
needed...
If you find this text helpful, please, support me and this website by signing my guestbook.