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]: Registry Appending[Next]: SUBST Command
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->Share Creation

Share Creation

The following shows how you can create a directory tree and share it. Note that Windows 2003 has a /GRANT parameter to assign privledges to the share, for other operating systems or for complex requirements you can use an external program (such as "SetACL.exe" - demonstrated below).

EXAMPLE: SHARE CREATION/REMOVAL

Note that share creation can be problematic if clients are accessing it, for this reason I tend to leave the share alone on uninstall (but you may not be able to do this).

;--- Create directories and set required access -----------------------------
<$Component "CreateShare" Create="Y" Directory_="INSTALLDIR" LM="Y">
   ;--- Create share directories --------------------------------------------
   <$DirectoryTree Key="SHARE_ROOT_DIR" Dir="C:\DATA\SomeDir"          MAKE="Y">
   <$DirectoryTree Key="SHARE_SUBDIR1"  Dir="[SHARE_ROOT_DIR]\SubDir1" MAKE="Y">
   <$DirectoryTree Key="SHARE_SUBDIR2"  Dir="[SHARE_ROOT_DIR]\SubDir2" MAKE="Y">

   ;--- Create appropriate permissions --------------------------------------
   <$TABLE "LockPermissions">
       ;--- Do everything for these "groups" --------------------------------
       #define ForTheseUsers  Users Administrators

       ;--- Define the changes ----------------------------------------------
       #{  SET ^@@Group={ }<$ForTheseUsers>^
           ;--- Need full access to the share -------------------------------
           #(
               <$Row
                   LockObject="SHARE_ROOT_DIR"
                        Table="CreateFolder"
                   Permission="<$PRIVILEGE_GENERIC_ALL>"
                       Domain="" User="<??SET_@@Group>"
               >
           #)
       #}
   <$/TABLE>
<$/Component>

;--- Create a custom action to create/delete share --------------------------
#data "CaDataShare"
   "SHARE_ROOT_DIR" '[SHARE_ROOT_DIR]'
#data
<$VbsCa Binary="Share.vbs" DATA=^CaDataShare^>
   ;--- INSTALL -------------------------------------------------------------
   <$VbsCaEntry "CreateShare">
       NetCmd("""MyShare={dir}"" /UNLIMITED /REMARK:""Short Comment (<$ProdInfo.ProductName>)""")
   <$/VbsCaEntry>

   ;--- UNINSTALL -------------------------------------------------------------
   <$VbsCaEntry "RemoveShare">
       NetCmd("MyShare /delete")
   <$/VbsCaEntry>

   ;=========================================================================
   sub NetCmd(Parameters)
   ;=========================================================================
       ;--- Get the share directory name ------------------------------------
       dim ShareDir : ShareDir = VbsCaCadGet("SHARE_ROOT_DIR")
       if  right(ShareDir, 1) = "\" then
           ShareDir = left(ShareDir, len(ShareDir)-1)
       end if

       ;--- Ignore the return code ------------------------------------------
       VbsCaRunSync "net share " & replace(Parameters, "{dir}", ShareDir), 0, ""
   end sub
<$/VbsCa>

;--- Shedule the above custom action ----------------------------------------
<$VbsCaSetup Binary="Share.vbs" Entry="CreateShare" Seq=Seq="StartServices-" Condition=^<$CONDITION_EXCEPT_UNINSTALL>^ DATA=^CaDataShare^ Key="ShareCreate">
<$VbsCaSetup Binary="Share.vbs" Entry="RemoveShare" Seq=Seq="StartServices-" Condition=^<$CONDITION_UNINSTALL_ONLY>^   DATA=^CaDataShare^ Key="ShareDelete">

EXAMPLE: SHARE CREATION + SetACL.EXE

#define SHARE_DIR           TheSharesName
#define SHARE_DIR_USER      UserIdWHichIsGivenSpecificAccess
<$Access "ACCESS_SHARE_DIR" Users="Administrators <$SHARE_DIR_USER> SYSTEM"  Access="GENERIC_ALL">
<$DirectoryTree Key="SHARE_DIR" Dir="<$SHARE_DIR>" MAKE="Y" REMOVE="Y" ACCESS="ACCESS_SHARE_DIR">
#data "CaData"
   "SHARE_DIR"    '[SHARE_DIR]'
   "SETACL.EXE"   "[INSTALLDIR]SetACL.exe"
#data
<$Component "SetACL.exe" Create="Y" Directory_="INSTALLDIR">
    <$File Source="SetACL.exe"  Comment=^Used to set security on the created share.^ KeyPath="Y">
<$/Component>
<$VbsCa Binary="CreateShare.vbs" DATA=^CaData^>
   ;--- INSTALL -------------------------------------------------------------
   <$VbsCaEntry "DuringInstall">
        ;--- Init -----------------------------------------------------------
        CaDebug 1, "Creating the share"
        dim SetAclExe : SetAclExe = VbsCaCadGetValidate("SETACL.EXE", "FILE")
        dim ShareDir  : ShareDir  = VbsCaCadGetValidate("SHARE_DIR",  "DIR")
        if  right(ShareDir, 1) = "\" then
            ShareDir = left(ShareDir, len(ShareDir)-1)
        end if

        ;--- Create the share (/GRANT is WIN2003+) --------------------------
        dim NetCmd
       'NetCmd   = "net share <$SHARE_DIR_SHARE>=" & ShareDir & " /UNLIMITED /GRANT:<$SHARE_DIR_USER>,FULL /REMARK:""A comment"""
        NetCmd   = "net share <$SHARE_DIR_SHARE>=" & ShareDir & " /UNLIMITED /REMARK:""A comment"""
        VbsCaRunSync NetCmd, 0, ""

        ;--- Grant permissions to the share ---------------------------------
        dim SetAclCmd
        SetAclCmd = """" & SetAclExe & """ -on ""\\.\<$SHARE_DIR_SHARE>"" -ot shr -actn ace -ace ""n:<$SHARE_DIR_SHARE>;p:full"" -ace ""n:Administrators;p:full"""
        VbsCaRunSync SetAclCmd, 0, ""
   <$/VbsCaEntry>
<$/VbsCa>
<$VbsCaSetup Binary="CreateShare.vbs" Entry="DuringInstall" Seq="DuplicateFiles-" Condition=^<$CONDITION_EXCEPT_UNINSTALL>^ DATA=^CaData^>


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006 & 2007 for the Windows SDK (Windows Installer) area.This external link was OK when tested at 15 Nov 2008Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: Registry Appending[Next]: SUBST Command


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Saturday November 15 2008 at 2:05pm
Visit MAKEMSI's Home PageThis external link was OK when tested at 7 Nov 2008

HTML page dated Mon, 29 Jan 2007 00:11:11 GMT
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006 & 2007 for the Windows SDK (Windows Installer) area.This external link was OK when tested at 15 Nov 2008