Question How would I set a Enviroment Variable on Several remote Machines from one Application

craneium

Member
Joined
Jun 29, 2009
Messages
5
Programming Experience
Beginner
I think my title covers the high level, but for indepth; i need to be able to connect to a machine through and ip and set a enviroment variable, i have over 60 machines in different states all on one network that i need to do this for as well as someother things for the machine. currently this is being done through a PCEXEC command in a batch file they want more control on how this operates. I just really have no idea where to even start looking for the enviroment variable change(setting one on a machine that the app is running is simple we all know that. but on a external machine im lost) on a remote machine. any one have any ideas.
 
You should be able to do that with the Win32_Environment WMI class. This example creates/sets a variable with local computer:
VB.NET:
Dim mc As New ManagementClass("Win32_Environment")
Dim mo As ManagementObject = mc.CreateInstance
mo.SetPropertyValue("UserName", "machine\user")
mo.SetPropertyValue("Name", "VarName")
mo.SetPropertyValue("VariableValue", "test value")
mo.Put()
mc.Dispose()
mo.Dispose()
This code has System.Management referenced and same namespace imported.

With ConnectionOptions and ManagementScope you can connect to remote computers using about same code. Remote connection could be something like this:
VB.NET:
Dim connection As New ConnectionOptions
connection.Username = "userName"
connection.Password = "password"
connection.Authority = "ntlmdomain:DOMAIN"

Dim scope As New ManagementScope("\\FullComputerName\root\CIMV2", connection)
scope.Connect()

Dim mc As New ManagementClass(scope, New ManagementPath("Win32_Environment"), New ObjectGetOptions)

'etc
 
Back
Top