windows - How to propagate environment variables to the system

Discussion in 'Ruby' started by armin@approximity.com, Jul 18, 2005.

  1. Guest

    Hi windows-experts,

    I would like to write a setup script that sets
    some variables for the entire system like an installer.
    When a new command prompt is opened, the values are now.

    I found this microsoft link and it seems possible via the
    registry.
    http://support.microsoft.com/kb/q104011/

    Does anybody happen to know the MS-World and have a working
    example?

    Thanks,
    -Armin
     
    , Jul 18, 2005
    #1
    1. Advertising

  2. gregarican Guest

    Armin wrote:

    > I would like to write a setup script that sets
    > some variables for the entire system like an installer.
    > When a new command prompt is opened, the values are now.




    You don't have to dig that deep in order to accomplish. This a quick
    way to get this done is through using the Ruby built-in ENV method. For
    example to create a new environmental variable called 'foo' and assign
    it the value 'bar' just issue the following:

    ENV['foo']='bar'

    then you can check the value by either issuing:

    ENV['foo']

    or else using the system method, passing along the set command:

    system('set foo')

    Does this help?
     
    gregarican, Jul 18, 2005
    #2
    1. Advertising

  3. Guest

    Sorry, but if you open a new command prompt window, foo is not known.

    Try this:
    set foo="34" in one command prompt

    open a new comand prompt
    type
    set
    foo will not show up.
     
    , Jul 18, 2005
    #3
  4. Armin,

    Take a look at ruby/ext/Win32API/lib/win32/registry.rb

    I guess this is what you want.

    Regards,

    Michael

    wrote:
    > Sorry, but if you open a new command prompt window, foo is not known.
    >
    > Try this:
    > set foo="34" in one command prompt
    >
    > open a new comand prompt
    > type
    > set
    > foo will not show up.
    >
    >
     
    Michael Neumann, Jul 18, 2005
    #4
  5. gregarican Guest

    armin wrote:

    > Try this:
    > set foo="34" in one command prompt
    >
    >
    > open a new comand prompt
    > type
    > set
    > foo will not show up.


    Oh sorry. Didn't see that you wanted these environmental variable to
    persist between separate NTVDM shells. Michael's advice regarding the
    registry.rb is on target...
     
    gregarican, Jul 18, 2005
    #5
  6. Alan Chen Guest

    To get the registry settings having to do with environment to stick
    without rebooting you also need to broadcast a message to notify
    processes of the change. Here's my revant code snippet: (Watch the urls
    in my comments. they may wrap badly)

    # broadcast a settings change
    # http://support.microsoft.com/?kbid=104011 the exact issue
    # WM_SETTINGCHANGE info
    #
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/wm_settingchange.asp
    # SendMessage info
    #
    http://msdn.microsoft.com/library/d...agesandmessagequeuesfunctions/sendmessage.asp

    require 'Win32API'
    SendMessage = Win32API.new("user32", "SendMessage", ['L', 'L', 'P',
    'P'], 'L')
    HWND_BROADCAST = 0xffff
    WM_SETTINGCHANGE = 0x001A
    puts SendMessage.Call(HWND_BROADCAST,WM_SETTINGCHANGE, 0,
    "Environment")

    It took me a week of head-scratching to figure out that registry.rb
    made the right changes, but they weren't being
    accepted quite correctly - especially when you want to use other Env
    variables in your definition. e.g. SRCTREE = %HOME%/blah/blah

    HTH,
    - alan
     
    Alan Chen, Jul 18, 2005
    #6
  7. You need to use setx.exe (downloadable from
    microsoft.com) and then flush a msg to
    WM_SETTINGCHANGE, an example of how to do this is at
    http://rubyforge.org/snippet/detail.php?type=3Dsnippet&id=3D56

    rgds

    Steve Callaway

    --- Michael Neumann <> wrote:

    > Armin,
    >=20
    > Take a look at
    > ruby/ext/Win32API/lib/win32/registry.rb
    >=20
    > I guess this is what you want.
    >=20
    > Regards,
    >=20
    > Michael
    >=20
    > wrote:
    > > Sorry, but if you open a new command prompt

    > window, foo is not known.
    > >=20
    > > Try this:
    > > set foo=3D"34" in one command prompt
    > >=20
    > > open a new comand prompt
    > > type
    > > set
    > > foo will not show up.
    > >=20
    > >=20

    >=20
    >=20
    >=20




    =09
    ____________________________________________________
    Start your day with Yahoo! - make it your home page=20
    http://www.yahoo.com/r/hs=20
    =20
     
    Steve Callaway, Jul 19, 2005
    #7
    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. greg
    Replies:
    1
    Views:
    331
    Morgan
    Dec 24, 2003
  2. Jim Potts
    Replies:
    3
    Views:
    377
    Felix McAllister
    Oct 3, 2003
  3. Phil
    Replies:
    5
    Views:
    245
  4. Disc Magnet
    Replies:
    0
    Views:
    177
    Disc Magnet
    Apr 18, 2011
  5. Propagate Identity to WebService

    , May 30, 2008, in forum: ASP .Net Security
    Replies:
    1
    Views:
    134
    Joe Kaplan
    May 30, 2008
Loading...

Share This Page