copyfile example
Previous  Top  Next

' The following scripts demonstrates how you can copy a configuration file located in the
' same directory as your Thinstalled EXE into the virtual filesystem each time the application starts
' one use for this is to allow you to have an external configuration file which is easy to edit after deployment
' because the copy occurs each time you run the application, any edits to the external version will
' be reflected in the virtual version

' For example if your Thinstalled EXE is running from \\server\share\myapp.exe, this script
' will look for a config file located at \\server\share\config.ini and copy it to the virtual filesystem location:
' c:\program files\my application\config.ini

' By putting this code in the OnFirstParentStart function , it will only be called once per execution
' Otherwise it will be executed for every child process as well
Function OnFirstParentStart
' TS_ORIGIN is set by Thinstall to indicate the full path to the Thinstalled EXE package
Origin = GetEnvironmentVariable("TS_ORIGIN")

' We want to chop off the filename from TS_ORIGIN, so find the last backslash and remove everything after this
LastSlash = InStrRev(Origin, "\")
SourcePath = Left(Origin, LastSlash)

' The source file to copy into the virtual environment is the package path plus config.ini

SourceFile = SourcePath + "Config.ini"

' The location we want to copy to may be in a different location on different computers if
' the "Program Files" directory is mapped to a different location than c:\
' The following call will let Thinstall expand a macro to get the correct location for the local PC
DestFile = ExpandPath("%ProgramFilesDir%\MyApplication\Config.ini")

' Use the FileSystemObject to check to make sure the Source file exist
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(SourceFile) Then
' If the source file exists, copy it into the virtual filesystem
' we are assuming the virtual directory %ProgramFilesDir%\MyApplication already exists in the package
objFSO.CopyFile SourceFile, DestFile, TRUE
End if

End Function