Working with logical paths - avoid hard-coding

One of the most common problems with scripting is that scripts have to be rewritten a number of times over the years, as network clients change. The primary reason for this is that logical paths are often hard-coded into scripts. FastTrack has simple, built-in functions that automatically resolve these, making multiple rewrites unnecessary.

Logical paths

What's the problem?

Directory paths under Windows XP and Windows 7 Here is a simple example: In an installation script for the 32-bit version of Office 2010, an icon is created for Microsoft Word on the common desktop. If all computers receiving the installation script are Windows XP, it could look like this:

CreateShortCut C:\Documents and Settings\All Users\Desktop, Word, _
C:\Program Files\Microsoft Office\Office14\WinWord.Exe

This makes perfect sense from a certain (limited) point of view. If all computers on the network are installed in the same way and all are running the same version of Windows, it might work, but probably not in the longer run, because a number of things can "break" the script. It will not work, for example, once machines with OS's newer than Windows XP are added, because the "common desktop" is in a completely different location on such machines.

Even with the same version of Windows, there can be a problem: If the company installs localized versions of Windows XP, both the common desktop directory and the program files directory will have different names. And if a 64-bit version of any version of Windows executes the script, the 32-bit program files directory will have a different name again.

It might not be the biggest problem in the world that the shortcut can't be created, but if it is the norm to hard-code paths, each and every script will eventually fail, as the clients in the network are upgraded or different versions get installed. So the solution is to simply use FSH's built-in functions to replace logical paths. Consider this rewrite of the same script line:

CreateShortCut [DesktopDir], Word, [ProgramFilesDirx86]\Microsoft Office\Office14\WinWord.Exe

This will work on any current or future version of Windows, because nothing is hard-coded. When you use these built-in functions, FastTrack will simply ask the operating system behind the scenes what the actual path is and use that in the executing context.

To the right, there is a partial screen-dump of the Engine Browser in the editor. Make it a habit to always use the functions under "Directory Paths", when you need to use any logical path.

Also please consider the table in the section below. Observe how different the same logical paths are on two of the most common versions of Windows. There is no reason to believe that things will get simpler in future versions, so do make it a habit to use these functions, thus eliminating the need to edit the same scripts over and over as your network clients change.

As a final tip, you can get an overview of the output of these functions on any machine in your network, by executing one of the example scripts. In the script editor, go to the "Documentation" tab and select "Show Logical Paths" under the "Insert Example Script" submenu and execute it on any computer, to see what all the logical paths are on that computer.

Comparison of default logical paths

The table below shows default paths on a Windows 7 64-bit computer and a Windows XP 32-bit computer with the same user "Test User" logged on.

 Windows 7 US - 64-bitWindows XP US - 32-bit
AppDataDirC:\ProgramDataC:\Documents and Settings\All Users\Application Data
CommonFilesDirC:\Program Files\Common FilesC:\Program Files\Common Files
CommonFilesDirx86C:\Program Files (x86)\Common FilesC:\Program Files\Common Files
DesktopDirC:\Users\Public\DesktopC:\Documents and Settings\All Users\Desktop
DocumentsDirC:\Users\Public\DocumentsC:\Documents and Settings\All Users\Documents
FavoritesDirC:\Users\Test User\FavoritesC:\Documents and Settings\All Users\Favorites
ProfilesDirC:\UsersC:\Documents and Settings
ProgramFilesDirC:\Program FilesC:\Program Files
ProgramFilesDirx86C:\Program Files (x86)C:\Program Files
ProgramsDirC:\ProgramData\Microsoft\Windows\Start Menu\ProgramsC:\Documents and Settings\All Users\Start Menu\Programs
StartMenuDirC:\ProgramData\Microsoft\Windows\Start MenuC:\Documents and Settings\All Users\Start Menu
StartUpDirC:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartupC:\Documents and Settings\All Users\Start Menu\Programs\Startup
TempDirC:\Users\Test User\AppData\Local\TempC:\Documents and Settings\Test User\Local Settings\Temp
TempFileC:\Users\Test User\AppData\Local\Temp\tmpD16.tmpC:\Documents and Settings\Test User\Local Settings\Temp\tmpD.tmp
TemplateDirC:\ProgramData\Microsoft\Windows\TemplatesC:\Documents and Settings\All Users\Templates
UserAppDataDirC:\Users\Test User\AppData\LocalC:\Documents and Settings\Test User\Local Settings\Application Data
UserCookiesDirC:\Users\Test User\AppData\Roaming\Microsoft\Windows\CookiesC:\Documents and Settings\Test User\Cookies
UserDesktopDirC:\Users\Test User\DesktopC:\Documents and Settings\Test User\Desktop
UserDocumentsDirC:\Users\Test User\DocumentsC:\Documents and Settings\Test User\My Documents
UserFavoritesDirC:\Users\Test User\FavoritesC:\Documents and Settings\Test User\Favorites
UserHistoryDirC:\Users\Test User\AppData\Local\Microsoft\Windows\HistoryC:\Documents and Settings\Test User\Local Settings\History
UserInternetCacheDirC:\Users\Test User\AppData\Local\Microsoft\Windows\Temporary Internet FilesC:\Documents and Settings\Test User\Local Settings\Temporary Internet Files
UserPersonalDirC:\Users\Test User\DocumentsC:\Documents and Settings\Test User\My Documents
UserProfileDirC:\Users\Test UserC:\Documents and Settings\Test User
UserProgramsDirC:\Users\Test User\AppData\Roaming\Microsoft\Windows\Start Menu\ProgramsC:\Documents and Settings\Test User\Start Menu\Programs
UserRecentDirC:\Users\Test User\AppData\Roaming\Microsoft\Windows\RecentC:\Documents and Settings\Test User\Recent
UserRoamingAppDataDir  C:\Users\Test User\AppData\RoamingC:\Documents and Settings\Test User\Application Data
UserSendToDirC:\Users\Test User\AppData\Roaming\Microsoft\Windows\SendToC:\Documents and Settings\Test User\SendTo
UserStartMenuDirC:\Users\Test User\AppData\Roaming\Microsoft\Windows\Start MenuC:\Documents and Settings\Test User\Start Menu
UserStartUpDirC:\Users\Test User\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\StartupC:\Documents and Settings\Test User\Start Menu\Programs\Startup
UserTemplateDirC:\Users\Test User\AppData\Roaming\Microsoft\Windows\TemplatesC:\Documents and Settings\Test User\Templates

Rating: 5 out of 5

"Use this as a replacement for VBScript and PowerShell"

"It's easy to include attractive GUI elements in FastTrack scripts, beyond the basic dialog boxes and text input that VBScript offers ... Another powerful feature is the ability to distribute scripts as Windows Installer (.msi) or standard .exe files. Although interesting in its own right, this ability results in a much more intriguing capability: to repackage -- or wrap -- software installers as .msi files without using snapshots. If you've ever created an .msi installer file from before-and-after system snapshots, for use with a software distribution system such as Group Policy or SCCM, then you know how hit-and-miss the results can be."

Read full review

Rating: 8 out of 10

"Faster than the rest"

"We found the FastTrack syntax to be more transparent and easier to learn than Microsoft's PowerShell – the editor in particular provided good support in this regard. the Script Editor offers a large number of options from the command set through to simple output of graphical elements, which cannot be achieved at all with PowerShell or other solutions or only with a significantly greater level of effort."

"Anyone wanting to tackle the many hurdles in everyday admin and especially anyone for whom logon scripts and client automation is a priority will benefit from the variety of functions offered by FastTrack."

Review in English      Review in German