Modify the Virtual Registry
The following script procedure modifies the virtual registry at runtime to load an external ODBC driver from
the same directory where the package executable file is located.
Modify the registry
1
Obtain the path to the package executable files.
Origin = GetEnvironmentVariable("TS_ORIGIN")
2
Find the last slash in the path and obtain the characters that precede the slash.
LastSlash = InStrRev(Origin, "\")
SourcePath = Left(Origin, LastSlash)
3
Form a new path to the ODBC DLL file located outside of the package.
DriverPath=SourcePath + "tsodbc32.dll"
4
Modify the virtual registry to point it to this location.
Set WSHShell = CreateObject("Wscript.Shell")
WSHShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\Transoft ODBC Driver\Driver,"
DriverPath
This modification causes the application to load the DLL from an external location.
.reg Example
The following script imports the registry values from an external .reg file into the virtual registry at runtime.
Function OnFirstParentStart
ExecuteVirtualProcess "regedit /s C:\tmp\somereg.reg"
End Function
Stopping a Service Example
The following script stops a virtual or native service when the main application quits.
Function OnFirstParentExit
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "net stop ""iPod Service"""
End Function
Copying a File Example
The following script sections shows how to copy a configuration file located in the same directory as the
captured executable file into the virtual file system each time the application starts. This script is useful for an
external configuration file that is easy to edit after deployment. Because the copy operation occurs each time
you run the application, any changes to the external version are reflected in the virtual version.
For example, if your captured executable file is running from \\server\share\myapp.exe, this script
searches for a configuration file located at \\server\share\config.ini and copies it to the virtual file
system location at C:\Program Files\my application\config.ini.
By putting this code in the OnFirstParentStart function, it is only called once each time the script runs.
Otherwise it runs for every child process.
Function OnFirstParentStart
VMware, Inc.
Chapter 9 Creating ThinApp Scripts
117