Windows - How to propagate environment variables to the system

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

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?

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.

Armin,

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

I guess this is what you want.

Regards,

   Michael

armin@approximity.com 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.

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

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/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/messagesandmessagequeues/messagesandmessagequeuesreference/messagesandmessagequeuesfunctions/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

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=snippet&id=56

rgds

Steve Callaway

···

--- Michael Neumann <mneumann@ntecs.de> wrote:

Armin,

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

I guess this is what you want.

Regards,

   Michael

armin@approximity.com 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.
>
>

____________________________________________________
Start your day with Yahoo! - make it your home page