2BrightSparks

What are Variables and Why are they used?

Author: Conrad Chung, 2BrightSparks Pte. Ltd.

Download PDF version [opens new window]

The Windows operating system (OS) has undergone a great deal of change since its first release in 1985.

One example is the changed path of ‘My Documents’ since post-Vista and/or later, which is \Users\[user name]\Documents, instead of \Documents and Settings\[user name]\My Documents\ as previously presented in Windows 2000, XP and Server 2003.

In order to make sure applications store your data in the correct place (regardless of which OS is used), variables can be used to request for and return the values of these paths dynamically.

In this article we will be looking at what variables are and how they can benefit users.

What are Variables?

A variable is a dynamic value that the operating system and other software use to provide an alias or placeholder to an unknown quantity that determines specific information it represents during a program run. The value of a variable is not known until its execution, which then replaces the variable with the value it represents. Hence, no prior knowledge is required what that actual value may be. Variables are often used by software programs in Windows to reference basic system information such as the location of the user profile settings, temporary files folders, the current date or time, etc.

Benefits of Variables

Variables are very convenient in situations where certain directories or parameters need to be referenced but these actual locations or names can vary from system to system. As variables are dynamic, it can be used to reference these changing values, which can vary from one system to another, or even within the same system.

Values may vary to match the current PC system’s setup and design. As each PC may be differently set up, the values may also differ between computer systems. With the use of variables, it is not required to know these values beforehand.

For example, each user who logs into Windows will be automatically given a unique path to his/her ‘My Documents’ folder that is generated by the operating system. An administrator that is tasked to back up this folder on every computer system in the company can simply set the backup source path to point to %CSIDL_PERSONAL% and the variable string will be replaced with the users ‘My Documents’ path when the backup runs.

Examples of Variables

When using variables, they need to be enclosed with percent signs (%) to be recognized. They are not case-sensitive. As there are many variables, it is not possible to list all of them, however the table below lists some commonly used ones:

Variable

Definition

Referenced Value or Path (May vary)

%USERPROFILE%

Location of current user’s profile directory.

C:\Documents and Settings\[username]\

%APPDATA%

Used by Windows to store application settings.

C:\Documents and Settings\[username]\Application Data\

%CSIDL_PERSONAL%

The virtual folder used to represent the My Documents item in Windows.

C:\Documents and Settings\[username]\My Documents\

%DATE%

Current date.

In short date format

%TIME%

Current time.

In short time format

%LABEL=?%

Reference to the hard drive with that label. Used for drive identification.

Example, if D drive is labelled as BACKUP, then it will be referred to as %LABEL=BACKUP%

%SERIAL=?%

Reference to the hard drive with that serial number. Used for drive identification.

Example, if the serial number of D drive is AB12-XYZ, then it will be referred to as %SERIAL=AB12-XYZ%

Using Variables in SyncBackPro, SyncBackSE, and SyncBackFree

In the backup and synchronization software, SyncBackPro, SyncBackSE, and SyncBackFree, variables can be used during the configuration of a profile. Various sections of the profile settings allow the use of variables. With the help of variables, users can create a single profile that can help to address dynamically changing values. For example, instead of using a drive letter path (example, D:\BACKUP) to point to a removable drive, which commonly get re-assigned by Windows with a new drive letter, Alternatives (Modify > Simple) can be used so that the backup profile locates the drive via Volume Label or Serial Number (of the drive) instead, by using the variables %LABEL=?% or %SERIAL=?% respectively. Hence, the profile will still work as expected even if a new drive letter is assigned by Windows when it is reconnected back to the system.

It is important to note that LABEL= and SERIAL= (etc.) Variables, are simply used internally to identify which drive-letter matches that Variable. The software will thereafter use that drive-letter when addressing the device. Hence the log will refer to the decoded drive-letter (for example, X:\...) and not to the actual Label or Serial values of the device.

There are several types of variables available for use in SyncBackPro/SE/Free, but only the commercial licensed programs – SyncBackPro and SyncBackSE support all of them. For a full listing of the variables supported, please review the Variables section of the Help in SyncBackPro and/or SyncBackSE. Note that SyncBackFree does not support some of the variables and a list of the unsupported variables can be found in the Variables Help section of the freeware.

The types of variables are broken into the following groups:

  • Registry variables
  • Windows environment variables
  • User defined (profile and group) variables and run-time variables
  • Group variables
  • SyncBack variables

The following settings pages can all use Variables (note that contextual Help is available via F1 on each page, generally with jump-links thereafter to the Variables section):

  • Simple (Source and/or Destination paths and/or Alternatives - %LABEL=?%, %SERIAL=?%, etc)
  • Simple > Change Filters
  • When > Insert
  • When > Program
  • Fast Backup
  • Compression > Advanced
  • FTP and FTP > Proxy (settings like Hostname, Username and SFTP Key (SyncBackPro only) support the use of Variables)
  • FTP > Firewall (External IP address)
  • Misc.
  • Programs Before and Programs Before > After
  • Log > Email Log and Log > Advanced
  • Network
  • Variables
  • Scripts
  • Backup Email

You may also make use of variables in the following areas:

  • Command Line Parameters
  • Runtime Scripts
  • Location Scripts
  • Restore
  • Comparison Programs under Differences window

Advanced users can also create their own custom variables by writing Scripts (supported by SyncBackPro only). There are example scripts (IncVar.vbs and IncVarEx.vbs) included in the program folder of SyncBackPro. These example scripts shows how to create and use customized variables in a profile. For more help, search for Scripting from within the Help of the program.

Please note that 2BrightSparks do not write bespoke scripts for people, nor provide bespoke assistance in doing so, as this is beyond the scope of our support. However, we provide the scripting facility, the Scripting section in the Help, and the examples provided in the program folder and the scripting webpage for users who wants to create their own scripts.

Summary

As variables are an integral part of how Windows functions, many users have likely used them without even being aware. Hopefully this article has helped you understand the value of variables, and if you have not used variables before, why not try using it today in our backup programs to see how it can benefit you?

For more information on Variables, please use the contextual Help in the program or you can visit the following sites:

https://ss64.com/nt/syntax-variables.html

https://en.wikipedia.org/wiki/Environment_variable

Noted Customers

© 2003-2024 2BrightSparks Pte. Ltd.  | Home | Support | Privacy | Terms | Affiliate Program

Home | Support | Privacy | Terms
© 2003-2024 2BrightSparks Pte. Ltd.

Back to top