Setting Windows environment variable

How can I set environment variable for windows(not for currect process)?
What command should I use?
I need functionality like setx.exe
For example I need get env variable, edit it and set it back.

ruby 1.8.5 win

···

--
Posted via http://www.ruby-forum.com/.

Look for the older thread "Setting Windows Environment Variables".
You'll probably have to mess with registry (see the alst post in the
thread)

J.

···

On 9/20/06, Pavel Ledin <puppet@rambler.ru> wrote:

How can I set environment variable for windows(not for currect process)?
What command should I use?
I need functionality like setx.exe
For example I need get env variable, edit it and set it back.

ruby 1.8.5 win

Jan Svitok wrote:

Look for the older thread "Setting Windows Environment Variables".
You'll probably have to mess with registry (see the alst post in the
thread)

Thanks, this works for me:

require 'win32ole'

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 = "<SYSTEM>"
  env_var.VariableValue = value
  env_var.Put_
end

var_name = 'ABC'
value = 'SOME_VALUE'

create_environment_variable(var_name, value)

···

--
Posted via http://www.ruby-forum.com/\.