(c) 2002 Lucian Wischik. This code is free, and anyone can do with it whatever they like (except sell it or claim ownership).
Packsetup2 is a tool for making self-extracting installers. It is particularly useful for the older versions of InstallShield that were bundled free with Visual Studio and Borland, and which lacked a built-in option to create self-extracting installers. Or, you can look at the source code to build your own slicker self-extracting installers.
Say you have already used InstallShield to generate setup.exe and data.cab and all the others. This program will zip them all up as the payload of a self-extracting installer. (It is called a payload because it is embedded into the self-extracting installer as a resource, not a separate file). When a user runs the installer, it will unzip its payload into a temporary directory, run the "setup.exe" that was part of the payload, and will schedule the temporary directory to be deleted upon next reboot.
The source code is written in plain Win32 API and should work with any C++ Windows compiler. Project files are included for Visual Studio .NET and for Borland C++Builder 5.
I hope that other programmers will be able to find this page when they search for code examples. I therefore write out the keywords present in the source code, to aid their search. GetFileAttributes, SHFILEOPSTRUCT, FO_DELETE, FOF_NOCONFIRMATION, FOF_NOERRORUI, FOF_SILENT, SHFileOperation, delete file in use, FindFirstFile, WIN32_FIND_DATA, FindNextFile, FindClose, MoveFileEx, MOVEFILE_DELAY_UNTIL_REBOOT, delete file upon next reboot, wininit.init, [rename], rename, delete file after reboot, PumpMessages, PeekMessage, Terminated, FindResource, SizeofResource, LoadResource, LockResource, HRSRC, HGLOBAL, OpenZip, GetZipItem, UnzipItem, CloseZip, SHELLEXECUTEINFO, ShellExecuteEx, RemoveDirectoryLater, RemoveDirectoryNow, shlobj.h, resupdate.h, zip.h, SHBrowseForFolder, initial directory, browse for folder, choose folder dialog, BFFM_INITIALIZED, BFFM_SETSELECTION, BFFN_SELCHANGED, SHGetPathFromIDList, ITEMIDLIST, BFFM_SETSTATUSTEXT, BFFM_ENABLEOK, center dialog, SetDlgItemUrl, url in dialog, hyperlink in dialog, blue underlined static text control, IMalloc, SHGetMalloc, BROWSEINFO, BIF_NONEWFOLDERBUTTON, BIF_USENEWUI, BIF_RETURNONLYFSDIRS, OPENFILENAME, GetSaveFileName, SetCapture, SetCursor, GetTempFileName, CreateZip, ZipAdd, add_rcdata, inject resource into EXE, resupdate, subclass, WM_CTLCOLORSTATIC, GetProp, SetProp, GetSysColor, TRANSPARENT, OPAQUE, SetBKColor, CreateFontIndirect, PE file format, IMAGE_DOS_HEADER, IMAGE_FILE_HEADER, IMAGE_DATA_DIRECTORY, IMAGE_OPTIONAL_HEADER32, IMAGE_NT_HEADERS, IMAGE_SECTION_HEADER, IMAGE_RESOURCE_DIRECTORY, IMAGE_RESOURCE_DIR_STRING, IMAGE_RESOURCE_DAT_ENTRY, IMAGE_RESOURCE_DIRECTORY_ENTRY, ExtractFileName, ChangeFileExt, SectionVirtualSize, SectionRawDataSize, DataDirectory, file alignment, section alignment, resource section, .rsrc, RVA, relocation segment, zip, unzip.