Using Environment Variables

You can use environment variables with SOTI MobiControl script commands. In general, an environment variable's name and value can be any ASCII character string. However, certain strings are reserved or have special meanings.

You can combine an environment variable with any command in place of a literal value. Simply enclose the environment variable in %. For example, %environmentvariable%. The script "showmessagebox %environmentvariable% would show a message box containing the value of variable %environmentvariable%.

Setting Environment Variable Values

You add values to the environment variables using the set command.

set var1=Hello gives var1 the value of Hello.

You can nest variables. For example, the two commands set var1=Hello and set var2=%var1% world! would grant var2 the value of Hello World!

You can also pull information from a string and use it in a variable. For example,

    set var1=Substring "Hi Hello World Goodbye" 4 11
    showmessagebox %var1%

would display Hello World on the device screen.

Reserved Variables

The system reserved variable errorlevel always has an integral value. You can assign integer values to this variable, but you cannot delete it.

For example, set errorlevel=9

Variable Initialisation Using System Information

Certain special strings allow you to extract information from the device and store it in an environment variable. You can extract this information from five sources.

Description Example
Text File

To extract a line from a text file, use the following format:


set myVar=TXT://policy.txt?LN=5 stores line 5 of the file policy.txt in the variable myVar
System Registry

To extract a value from the registry, use the following format:


set myVar=REG://HKEY_LOCAL_MACHINE\Windows CE Tools?VN=Platform
.ini file

To extract the value from an .ini file, use the following format:


set myVar=INI://settings.ini?SC=Config&NM=PreferredOption
Exit Code

To store the exit code of an executable program, use the following format:


Note: Not supported on Windows CE or Pocket PC devices.
set myVar=EXE://scansystem /o runs the command scansystem /o and stores its return code in myVar

To store the first line out output from an executable program, use the following format:


Note: Only supported on Windows Desktop Classic devices.
set myVar=STDOUT://checkmessages runs the command checkmessages and stores the first line of its output in myVar