Working with environment variables
Environment variables are a set of named values that can affect the way processes and applications run on a computer. NAV has a built-in function to reference these variables and lets you change the way it functions.
How to do it...
Create a new codeunit from Object Designer.
Add the following code to the
OnRun
trigger:MESSAGE(' OS: %1\Temp: %2\WinDir: %3', ENVIRON('OS'), ENVIRON('TEMP'), ENVIRON('WINDIR'));
Save and close the codeunit.
How it works...
The ENVIRON
function takes in a single string and returns a string. Our codeunit uses the ENVIRON
function to return three common environment variables: the name of the operating system, the path to the temporary folder for the current user, and the path to the Windows installation directory.
In Windows 7, in order to see all of the options available to the ENVIRON
command, simply right-click on My Computer and go to Properties.
Click on Advanced system settings, the Advanced tab, and then on the Environment Variables...