I am trying to write a script to change a Windows
environment variable on a bunch of computers. I have the
following VB Script, however it only makes the change on
the local computer. What am I doing wrong? Thanks in
advance!
Const ForReading = 1
dim objWMIService, colAdapters, StrComputer, objAdapter,
orcachange, strcurrentvalue
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\servers.txt", ForReading)
i = 0
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
Loop
For Each objItem in objDictionary
StrComputer = objDictionary.Item(objItem)
Set objWMIService = GetObject("winmgmts:\\" & StrComputer
&"\root\cimv2")
set objshell = createobject("wscript.shell")
set oracchange = objshell.environment("SYSTEM")
strcurrentvalue = oracchange("TNS_ADMIN")
oracchange("TNS_ADMIN") = "\\\\thor\\TNS_ADMIN_GENERAL$"
Next
Try something like this instead (adapted from the MSDN
documentation for WMI's Win32_Environment call) ...
Each objItem in objDictionary
StrComputer = objDictionary.Item(objItem)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set PathVariables = objWMIService.ExecQuery( _
"Select * from Win32_Environment where " _
& "Name = 'Path' and Username='<system>'" )
NewEnvValue = ";%UserProfile%\Script;" _
& "%UserProfile%\Script\Testing"
For Each EnvVar in PathVariables
sPath = EnvVar.VariableValue
if Instr(1, sPath, NewEnvValue, vbTextCompare) = 0 Then
EnvVar.VariableValue = sPath & NewEnvValue
EnvVar.Put_
End if
wsh.echo EnvVar.VariableValue
Next
Next
Tom Lavedas
===========
>.
>