\Tips and TricksFile and DirectoryShare 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="StartServices-" Condition=^<$CONDITION_EXCEPT_UNINSTALL>^ DATA=^CaDataShare^ Key="ShareCreate">
<$VbsCaSetup Binary="Share.vbs" Entry="RemoveShare" 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^>