Create a self-extracting .exe with 7zip

 

One interesting situation that i was in a while back was that a customer wanted a big bundle of apps installed on several machines. Upon inspecting the bundle, this was made with an Install.VBS and contained more than 20 apps. Oddly enough, each MSI had an outside media (nope, not cabs, pure media).

In this case several problems came into mind, like the fact that some MSIs had long paths that exceeded the 256 characted limit in the Windows explorer. Another problem was the download time for all the 500k+ files.

So instead, i decided to go with the easy route: 7Zip.

7Zip is actually quite an interesting program and kudos to the dev team.

To create a self-extracting exe file, right click the folder you want to archive>7zip>Add to Archive.

In the dialog that appears leave the archive format 7z and check “Create SFX Archive” on the right.

In order to extract the media in a VBScript place the following code:

 


Set WshShell = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
ParentFolder = FSO.GetParentFolderName(WScript.ScriptFullName)
sParentFolder = ParentFolder & "\"

 

ExeLocation = sParentFolder & "Archive.exe"

Extract = chr(34) & ExeLocation & chr(34) & " -o" & chr(34) & sParentFolder & " -y"

WshShell.run Extract,0,true

 

The above code will extract the Archive.exe into the sParentFolder, where sParentFolder is the location where the script is.

Sharing is caring!

Leave a comment

Your email address will not be published. Required fields are marked *

4 + ten =