Using DOS Environment Variables in Self-Extracting EXE’s

This post pertains to using the Chilkat Self-Extracting EXE utility.

The goal is to create a self-extracting EXE such that the files are unzipped into the directory where the EXE is located.  To do this, the %CD% environment variable is used in a DOS command line.

The intent is to use the -d option with “%CD%” so that the environment variable is run when the self-extracting EXE runs — but NOT when creating the self-extracting EXE.  The trick is to use a double-percent sign:

In batch files, the percent sign may be "escaped" by using a double percent sign ( %% ).
That way, a single percent sign will be used within the command line.

The DOS command to create the self-extracting EXE might look like this:

CHILKATZIPSE.EXE -u myUnlockCode -autoexit -d %%CD%% -sm -sp -RUN doSomething.bat