Create or Modify an Environmental Variable with a script

Hi

Was looking to create create an environmental variable to point to a licence server, however the script overwrites the existing values.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\" & strComputer & "rootcimv2")

Set objVariable = objWMIService.Get("Win32_Environment").SpawnInstance_

objVariable.Name = "LM_Licence_File"
objVariable.UserName = ""
objVariable.VariableValue = "27004@servername"
objVariable.Put_

Is there a way to set it so that if the variable name already exists (in this case LM_Licence_File)it adds to it (except when the value already exists)



Have you tried this, it should set the variable permanently:



Have you tried this, it should set the variable permanently:



Or did I misunderstand the question, do you want to concatenate a new value if it's already set? In that case something like:



And I guess the cleaner way to do that would be:





Share this

Related Posts

There was an error in this gadget