Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Setting Windows environment variable

Reply
Thread Tools

Setting Windows environment variable

 
 
Pavel Ledin
Guest
Posts: n/a
 
      09-20-2006
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/.

 
Reply With Quote
 
 
 
 
Jan Svitok
Guest
Posts: n/a
 
      09-20-2006
On 9/20/06, Pavel Ledin <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
 
Pavel Ledin
Guest
Posts: n/a
 
      09-20-2006
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/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting an environment variable. Ashton Fagg Python 1 01-03-2012 08:29 PM
70-284 Lab Environment, Need Virtual Environment brooklynbridge508@hotmail.com MCSA 4 05-02-2007 09:49 AM
Setting an environment variable from another environment variable marcwentink@hotmail.com Java 5 04-04-2007 10:39 PM
setting an environment variable (for libxml2) Une bévue Ruby 3 03-10-2006 07:20 AM
URGENT: Need help in setting environment variable.. pls help Rahul S. C Programming 3 11-01-2004 10:53 AM



Advertisments