Create env variable (VBScript)

This code can be found in Chapter 2 of Windows Server Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' This code creates a new system environment variable called FOOBAR.
' ---------------------------------------------------------------
' From the book "Windows Server Cookbook" by Robbie Allen
' ISBN: 0-596-00633-0
' ---------------------------------------------------------------

' ------ SCRIPT CONFIGURATION ------
strVarName = "FOOBAR"
strVarValue = "Foobar Value"
strComputer = "."
' ------ END CONFIGURATION ---------
set objVarClass = GetObject("winmgmts:\\" & strComputer & _
                            "\root\cimv2:Win32_Environment")
set objVar = objVarClass.SpawnInstance_
objVar.Name = strVarName
objVar.VariableValue = strVarValue
objVar.UserName = "<SYSTEM>"
objVar.Put_
WScript.Echo "Created environment variable " & strVarName

This code has been viewed 6284 times.

New from the creators of TechTasks.com: StatSheet.com