As an extension of the theme I’ve been blogging about lately of “interfacing with other types of applications” in VBScript, I’d like to share with you a snippet of VBScript code that will allow you to read environment variables from your system. This will allow you to determine a great deal of information, since many applications use environment variables for configuration information– and the OS itself does as well, like the server that logged you on is %logonserver%.
There are two types of environment variables:
- System variables, which are available to every process across the system
- Process variables, which are only available to the process and disappear when the process is completed. These are sometimes referred to a user environment variables.
You can see examples of each of these environment variables being used below via the “Environment” method of the Wscript.Shell object.
Set WshShell = WScript.CreateObject(“WScript.Shell”)
‘create a Process (user profile) Level environment variable object
Set WshProccessEnv = WshShell.Environment(“Process”)
‘create a System Level environment variable object
Set WshSysEnv = WshShell.Environment(“System”)
‘display a system environment variable
‘display a user profile level environment variable