[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Setting Windows Environment Variables

Cameron, Gemma (UK)

8/15/2006 1:31:00 PM


Hi Austin,

Thanks for all that - but I think you missed the point. I need to set up the env path of the machine permanantly. Say we wanted to bring in a new build machine or the old one died/I spilled coffee on it... :s The point being that I want the environment variables on the machine, not in the shortcut/script/kernal I'm running. I have done something similar before using NSIS which worked great as lots of programs had to also be installed and programs placed in folders etc.

And by thinking in ant - I'm new to ruby and with Ant I know there's pretty much nothing I can't do - it's mostly all been tasked before so I merely sent a few parameter through and what I want happens magically!

I'm sure it'll be even easier with Ruby but I'm still finding my feet. ( :

Thanks a lot for the input everyone, it's greatly appreciated! Especially such great information in such massive quantities and so quickly!!!

Regards

Gemma Cameron
Senior Software Engineer
Eurofighter ESS (SHM)

tel: 01772 858492


-----Original Message-----
From: Austin Ziegler [mailto:halostatue@gmail.com]
Sent: 15 August 2006 14:01
To: ruby-talk ML
Subject: Re: Setting Windows Environment Variables


*** WARNING ***

This mail has originated outside your organization,
either from an external partner or the Global Internet.
Keep this in mind if you answer this message.

On 8/15/06, Lyndon Samson <lyndon.samson@gmail.com> wrote:
> You might be in luck.

Not really. You can't change the environment of an already running
process that isn't yourself. Even if one were to go into the System
control panel and change the environment variables, any shortcut
launchers (as I often use) will themselves need to be relaunched to
take advantage of the updated environment variables. Certainly, there
must be a way to refresh the internal environment variable table based
on the current registry settings, but that would be based on a global
signal.

I'm not sure what the OP's post about thinking in "ant" is, because
Ant would be similarly limited. This is not a Ruby limitation; it is
one of the few limitations that is essentially cross-platform and
found on every platform in existence to the best of my knowledge. The
only reason that shell script functions and DOS/Winodws batch files
can affect the current level's environment variables is that they are
not in a separate process and are therefore just modifying the current
process's environment variables.

-austin
--
Austin Ziegler * halostatue@gmail.com * http://www.halo...
* austin@halostatue.ca * http://www.halo...feed/
* austin@zieglers.ca



********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

2 Answers

Curt Hibbs

8/15/2006 4:55:00 PM

0

You have to set entries in the Windows registry to do this
permanently. I'm not in a position at the moment to be able to look up
the details, but perhaps just knowing this can lead you to finding the
answer.

Curt

On 8/15/06, Cameron, Gemma (UK) <gemma.cameron@baesystems.com> wrote:
>
> Hi Austin,
>
> Thanks for all that - but I think you missed the point. I need to set up the env path of the machine permanantly. Say we wanted to bring in a new build machine or the old one died/I spilled coffee on it... :s The point being that I want the environment variables on the machine, not in the shortcut/script/kernal I'm running. I have done something similar before using NSIS which worked great as lots of programs had to also be installed and programs placed in folders etc.
>
> And by thinking in ant - I'm new to ruby and with Ant I know there's pretty much nothing I can't do - it's mostly all been tasked before so I merely sent a few parameter through and what I want happens magically!
>
> I'm sure it'll be even easier with Ruby but I'm still finding my feet. ( :
>
> Thanks a lot for the input everyone, it's greatly appreciated! Especially such great information in such massive quantities and so quickly!!!
>
> Regards
>
> Gemma Cameron
> Senior Software Engineer
> Eurofighter ESS (SHM)
>
> tel: 01772 858492
>
>
> -----Original Message-----
> From: Austin Ziegler [mailto:halostatue@gmail.com]
> Sent: 15 August 2006 14:01
> To: ruby-talk ML
> Subject: Re: Setting Windows Environment Variables
>
>
> *** WARNING ***
>
> This mail has originated outside your organization,
> either from an external partner or the Global Internet.
> Keep this in mind if you answer this message.
>
> On 8/15/06, Lyndon Samson <lyndon.samson@gmail.com> wrote:
> > You might be in luck.
>
> Not really. You can't change the environment of an already running
> process that isn't yourself. Even if one were to go into the System
> control panel and change the environment variables, any shortcut
> launchers (as I often use) will themselves need to be relaunched to
> take advantage of the updated environment variables. Certainly, there
> must be a way to refresh the internal environment variable table based
> on the current registry settings, but that would be based on a global
> signal.
>
> I'm not sure what the OP's post about thinking in "ant" is, because
> Ant would be similarly limited. This is not a Ruby limitation; it is
> one of the few limitations that is essentially cross-platform and
> found on every platform in existence to the best of my knowledge. The
> only reason that shell script functions and DOS/Winodws batch files
> can affect the current level's environment variables is that they are
> not in a separate process and are therefore just modifying the current
> process's environment variables.
>
> -austin
> --
> Austin Ziegler * halostatue@gmail.com * http://www.halo...
> * austin@halostatue.ca * http://www.halo...feed/
> * austin@zieglers.ca
>
>
>
> ********************************************************************
> This email and any attachments are confidential to the intended
> recipient and may also be privileged. If you are not the intended
> recipient please delete it from your system and notify the sender.
> You should not copy it or use it for any purpose nor disclose or
> distribute its contents to any other person.
> ********************************************************************
>
>

gordon

8/15/2006 5:11:00 PM

0

You can use WMI via win32ole:


require 'win32ole'

def append_to_system_path(path)
wmi = WIN32OLE.connect("winmgmts:\\\\.\\root\\cimv2")
wql = "Select * from Win32_Environment Where Name = 'PATH' and UserName = '<SYSTEM>'"
system_path = wmi.ExecQuery(wql)

system_path.each do |i|
i.VariableValue += ";#{path}"
i.Put_
end

end

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


path = "C:\\something_you_want_appended"
append_to_system_path(path)


var_name = 'test'
value = 'SOME_VALUE'

create_environment_variable(var_name, value)