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

On 9/20/06, Pavel L. [email protected] 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

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.

Jan S. 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 = “”
env_var.VariableValue = value
env_var.Put_
end

var_name = ‘ABC’
value = ‘SOME_VALUE’

create_environment_variable(var_name, value)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs