[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Setting Windows environment variable

Pavel Ledin

9/20/2006 9:20:00 AM

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-....

2 Answers

Jano Svitok

9/20/2006 9:38:00 AM

0

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
>

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.

Pavel Ledin

9/20/2006 10:01:00 AM

0

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-....