Setting Windows environment variable

Discussion in 'Ruby' started by Pavel Ledin, Sep 20, 2006.

  1. Pavel Ledin

    Pavel Ledin Guest

    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/.
    Pavel Ledin, Sep 20, 2006
    #1
    1. Advertising

  2. Pavel Ledin

    Jan Svitok Guest

    On 9/20/06, Pavel Ledin <> 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 Svitok, Sep 20, 2006
    #2
    1. Advertising

  3. Pavel Ledin

    Pavel Ledin Guest

    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/.
    Pavel Ledin, Sep 20, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rahul S.
    Replies:
    3
    Views:
    601
    Flash Gordon
    Nov 1, 2004
  2. Replies:
    5
    Views:
    653
  3. Ashton Fagg

    Setting an environment variable.

    Ashton Fagg, Jan 3, 2012, in forum: Python
    Replies:
    1
    Views:
    242
    Nobody
    Jan 3, 2012
  4. Afaque Ahmad
    Replies:
    2
    Views:
    679
    Brian Schröder
    May 26, 2005
  5. Une bévue
    Replies:
    3
    Views:
    137
    Une bévue
    Mar 10, 2006
Loading...

Share This Page