MAKEMSI quickly and reliably creates MSI files in a non-programmatic way
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
[Bottom][Contents][Prev]: Share Creation[Next]: Extract Binary at Install Time
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Tips and Tricks->File and Directory->SUBST Command

SUBST Command

The "MakeCab.EXE" utility may have issues with file/path length of some of the files you add with the "file" and "files" commands. In this case, one possible solution involves using the Windows "subst" command to create a drive letter which points to a much longer "path".

You could of course use a batch file to perform the substitution but this demonstrates how it can be part of the MAKEMSI script.

SYNTAX of the Windows "SUBST" command

Associates a path with a drive letter.

SUBST [drive1: [drive2:]path]
SUBST drive1: /D

  drive1:        Specifies a virtual drive to which you want to assign a path.
  [drive2:]path  Specifies a physical drive and path you want to assign to
                 a virtual drive.
  /D             Deletes a substituted (virtual) drive.

Type SUBST with no parameters to display a list of current virtual drives.

EXAMPLE: Using the "SUBST" Command

This shows how to use the MAKEMSI "subst" command I define below:

;--- Add file "C:\Tmp\sfx\MakeSFX.exe\MakeSFX.exe" --------------------------
#define SomePossiblyReallyLongPath C:\Tmp\sfx\MakeSFX.exe
<$Subst Drive="F" ToDir="<$SomePossiblyReallyLongPath>" Exists="MakeSFX.exe">
<$Files "F:\MakeSFX.exe" DestDir="INSTALLDIR">

In the above I chose a drive letter which is not used for any other purpose!

Defining the SUBST Command

This defines the "SUBST" command we used in the example above, the best place for this is of course once off in a personal MAKEMSI configuration file.

#(
    ;--- Version 07.261 -----------------------------------------------------
    #define Subst

    #evaluate ^^ ^<$@@Rexx4Subst {$?}>^
#)
#DefineRexx '@@Rexx4Subst'
    ;--- Get parameters and "clean up" --------------------------------------
    @@Drive  = '{$Drive}';              ;;Drive letter we will use for this purpose
    @@ToDir  = '{$ToDir}';              ;;Directory where we want the drive letter to "point" to
    @@Exists = '{$Exists}';             ;;Can contain RELATIVE path ("RelPath\SomeFile.txt")
    if  length(@@Drive) = 1 then
        @@Drive = @@Drive || ':';
    if  right(@@ToDir, 1) = '\' then
        @@ToDir = left(@@ToDir, length(@@ToDir)-1);
    @@FileSubst = @@Drive || '\' || @@Exists;
    @@FileToDir = @@ToDir || '\' || @@Exists;

    ;--- Make sure the validation filename we were passed exists! -----------
    if  FileQueryExists(@@FileToDir) = '' then
        call error 'The file you passed to the MAKEMSI "SUBST" command is invalid.',, 'We didn''t find the file "' || @@FileToDir || '".';

    ;--- If we can't find the file we assume we need to subst the drive -----
    if  FileQueryExists(@@FileSubst) =  '' then
    do
        ;--- Can't find the file, indicate we will create the drive letter ---
        call Info "Didn't find: " || @@FileSubst;
        call Info 'SUBST ' || @@Drive || ' ==> ' || @@ToDir;

        ;--- Do the subst (windows) command ---------------------------------
        @@Cmd = 'subst.exe ' || @@Drive || ' "' || @@ToDir || '"';
        @@ConsoleFile = GetEnv('TMP') || '\SUBST_' || left(@@Drive, 1) || '.TXT';
        @@Rc  = AddressCmd(@@Cmd || ' > "' || @@ConsoleFile || '" 2>&1');

        ;--- See if it worked -----------------------------------------------
        if  FileQueryExists(@@FileSubst) = '' then
            call error 'We performed the Windows "SUBST" command with return code ' || @@Rc,, 'We didn''t find the existed file "' || @@FileSubst || '".';
    end;
#DefineRexx

Note that as written above I don't remove the drive letter at the end of the build and I only perform the subst once if required.


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: Share Creation[Next]: Extract Binary at Install Time


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Saturday May 28 2022 at 3:11pm
Visit MAKEMSI's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.