4.5

Table Of Contents
VMware, Inc. 107
Chapter 9 Creating ThinApp Scripts
Modify the Virtual Registry
ThefollowingscriptproceduremodifiesthevirtualregistryatruntimetoloadanexternalODBCdriverfrom
thesamedirectorywherethepackageexecutablefileislocated.
To modify the registry
1 Obtainthepathtothepackageexecutablefiles.
Origin = GetEnvironmentVariable("TS_ORIGIN")
2Findthelastslashinthepathandobtainthecharactersthatprecedetheslash.
LastSlash = InStrRev(Origin, "\")
SourcePath = Left(Origin, LastSlash)
3FormanewpathtotheODBC DLLfilelocatedoutsideofthepackage.
DriverPath=SourcePath + "tsodbc32.dll"
4Modifythevirtualregistrytopointittothislocation.
Set WSHShell = CreateObject("Wscript.Shell")
WSHShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\Transoft ODBC Driver\Driver,"
DriverPath
ThismodificationcausestheapplicationtoloadtheDLLfromanexternallocation.
.reg Example
Thefollowingscriptimportstheregistryvaluesfromanexternal.regfileintothevirtualregistryatruntime.
Function OnFirstParentStart
ExecuteVirtualProcess "regedit /s C:\tmp\somereg.reg"
End Function
Stopping a Service Example
Thefollowingscriptstopsavirtualornativeservicewhenthemainapplicationquits.
Function OnFirstParentExit
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "net stop ""iPod Service"""
End Function
Copying a File Example
Thefollowingscriptsectionsshowshowtocopyaconfigurationfilelocatedinthesamedirectoryasthe
capturedexecutablefileintothevirtualfilesystemeachtimetheapplicationstarts.Thisscriptisusefulforan
externalconfigurationfilethatiseasytoeditafterdeployment.Becausethecopyoperation
occurseachtime
youruntheapplication,anychangestotheexternalversionarereflectedinthevirtualversion.
Forexample,ifyourcapturedexecutablefileisrunningfrom\\server\share\myapp.exe,thisscript
searchesforaconfigurationfilelocatedat\\server\share\config.iniandcopiesittothevirtualfile
systemlocationat
C:\Program Files\my application\config.ini.
ByputtingthiscodeintheOnFirstParentStartfunction,itisonlycalledonceeachtimethescriptruns.
Otherwiseitrunsforeverychildprocess.
Function OnFirstParentStart