I'm writing a little Ruby script ( on Windows XP) that needs check ENV for a few things ( specifically if a few things are set and if they are if they are set to the proper values. If not and and if they are not present it needs to modify and ENV or overwrite value. For instance if ENV["CUSTOM_PATH"] doesn't contain C:\some_program\bin or it doesn't exist then it needs to be added and or modified and ENV saved.
Just to clarify - I want the change to be permanent and have system-wide effect, not just the current session. Basically I'm trying to create a shortcut for going to My COmputer -> Properties -> Advanced -> System Variables -> Changing a bunch of them by hand -> save. I need to do it 5-6 times a day while I'm developing and it's getting annoying pretty fast :-)
I got it all worked out except for last part - I can't figure out how to save ENV WITHOUT resorting to shell commands.
Is there anyway to do it directly from ruby, not shell?
Thank you!
WORKAROUND:
As specified in accepted answer - it's not possible to do. However my work around is dependent on combination of ruby and a command line utility called SETENV.EXE develped by Vincent Fatica. It's more than a decade old at this point but works fine in windows XP ( didn't test under Windows 7 yet). It works better than setx utility available from ms IMHO. At lest of deleting stuff.
Here is a short example of a method using it:
def switch_ruby_env
if RUBY_VERSION.match("1.8.7").nil?
`setenv -m CUSTOM_PATH " "`
else
`setenv -m CUSTOM_PATH -delete`
end
end