Re: Setting Windows Environment Variables

Hi Austin,

Thanks for all that - but I think you missed the point. I need to set up
the env path of the machine permanantly. Say we wanted to bring in a new
build machine or the old one died/I spilled coffee on it… :s The point
being that I want the environment variables on the machine, not in the
shortcut/script/kernal I’m running. I have done something similar before
using NSIS which worked great as lots of programs had to also be
installed and programs placed in folders etc.

And by thinking in ant - I’m new to ruby and with Ant I know there’s
pretty much nothing I can’t do - it’s mostly all been tasked before so I
merely sent a few parameter through and what I want happens magically!

I’m sure it’ll be even easier with Ruby but I’m still finding my feet. (
:

Thanks a lot for the input everyone, it’s greatly appreciated!
Especially such great information in such massive quantities and so
quickly!!!

Regards

Gemma Cameron
Senior Software Engineer
Eurofighter ESS (SHM)

tel: 01772 858492

You have to set entries in the Windows registry to do this
permanently. I’m not in a position at the moment to be able to look up
the details, but perhaps just knowing this can lead you to finding the
answer.

Curt

You can use WMI via win32ole:

require ‘win32ole’

def append_to_system_path(path)
wmi = WIN32OLE.connect(“winmgmts:\\.\root\cimv2”)
wql = “Select * from Win32_Environment Where Name = ‘PATH’ and
UserName = ‘’”
system_path = wmi.ExecQuery(wql)

system_path.each do |i|
i.VariableValue += “;#{path}”
i.Put_
end

end

def create_environment_variable(var_name, value)
wmi = WIN32OLE.connect(“winmgmts:\\.\root\cimv2”)
env_var = wmi.Get(‘Win32_Environment’).SpawnInstance_

env_var.Name = var_name
env_var.UserName = “”
env_var.VariableValue = value
env_var.Put_
end

path = “C:\something_you_want_appended”
append_to_system_path(path)

var_name = ‘test’
value = ‘SOME_VALUE’

create_environment_variable(var_name, value)