Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > windows - How to propagate environment variables to the system

Reply
Thread Tools

windows - How to propagate environment variables to the system

 
 
armin@approximity.com
Guest
Posts: n/a
 
      07-18-2005
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

 
Reply With Quote
 
 
 
 
gregarican
Guest
Posts: n/a
 
      07-18-2005
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?

 
Reply With Quote
 
 
 
 
armin@approximity.com
Guest
Posts: n/a
 
      07-18-2005
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.

 
Reply With Quote
 
Michael Neumann
Guest
Posts: n/a
 
      07-18-2005
Armin,

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

I guess this is what you want.

Regards,

Michael

http://www.velocityreviews.com/forums/(E-Mail Removed) 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.
>
>




 
Reply With Quote
 
gregarican
Guest
Posts: n/a
 
      07-18-2005
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...

 
Reply With Quote
 
Alan Chen
Guest
Posts: n/a
 
      07-18-2005
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/de...tingchange.asp
# SendMessage info
#
http://msdn.microsoft.com/library/de...endmessage.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

 
Reply With Quote
 
Steve Callaway
Guest
Posts: n/a
 
      07-19-2005
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....nippet&id=3D56

rgds

Steve Callaway

--- Michael Neumann <(E-Mail Removed)> 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
> (E-Mail Removed) 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


 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: I'd appreciate some help in understanding how posts propagate. Mike Easter Computer Support 5 03-24-2010 06:57 PM
Propagate import for all modules in a package. Phil Python 5 07-17-2009 06:44 PM
update to c# library would not propagate greg ASP .Net 1 12-24-2003 02:14 AM
Guess who's helping propagate Swen? Max Quordlepleen Computer Support 8 09-27-2003 04:34 AM



Advertisments