For Programmers: Free Programming Magazines  


Home > Archive > Tcl > October 2005 > windows; user env vars









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author windows; user env vars
Niv (KP)

2005-10-12, 8:05 am

Is it possible to set (& change) user env variables, (permanently) in
windows using tcl?

I have scripts to create/upissue etc projects for Mentors
HDL_Designer, but I need to update envirnment variables for
it all to work with the Mentor tool.

Any help much appreciated, Niv.

Arjen Markus

2005-10-12, 8:05 am

I have used the script by Steve Cassidy extension to manipulate the
Start menu and so on - see http://wiki.tcl.tk/1844

This uses the dde extension. I am not sure whether you need that for
this particular task. It may be necessary to use the registry
extension. See examples on the Wiki.

Another thing is:
If you start the application via Tcl, you can preset the various
environment variables without bothering how to get that into the
Windows system.

Regards,

Arjen

Niv (KP)

2005-10-12, 7:00 pm

I cannot guarantee the app will be started by a tcl call, very unlikely
in fact.
So, what I need to do is for tcl to create windows environment vars &
then
modify my scripts to use soft paths rather than full hard paths.

This is because once the project file is updated, it needs to keep the
same
soft paths to maintain links within the created design.

The update scripts would be simpler as the project files wouldn't
change, but
the env var would, to match the updated directory structure.

e.g. env var: MY_PATH = D:/PROJECT/CHIP/DESIGN/ISSUE_1A
and my tcl scripts would generate $MY_PATH as the
top level directory.

tcl update scripts would build new directory structure, i.e
/../ISSUE1B, so the env var would also need a corresponding change.

I don't know how to do this, and letting tcl play with the registry is
not something i want to do!

Regards, Niv.

Darren New

2005-10-12, 7:00 pm

Niv (KP) wrote:
> I don't know how to do this, and letting tcl play with the registry is
> not something i want to do!


Since that's where Windows stores the environment variable settings,
you're not going to be able to set environment variables that persist
past the process without playing with the registry.

Start up regedit and look in HKEY_CURREN_USER\Environment

--
Darren New / San Diego, CA, USA (PST)
Neither rocks nor slush nor salted rims
shall keep us from our appointed rounds.
Niv (KP)

2005-10-18, 7:57 am

OK, my work PC is locked as far as C: drive is concerned, but I can
still
go into My Computer/Properties/Advanced/Env Vars and set up user
variables;
system variables is locked.

So, how do I use tcl to set up a user env var. I'm really struggling
with this!

Donal K. Fellows

2005-10-18, 7:02 pm

Niv (KP) wrote:
> So, how do I use tcl to set up a user env var. I'm really struggling
> with this!


Use the registry package to add a key and value to HKCU/Environment

Donal.
Niv (KP)

2005-10-20, 7:00 pm

Thanks for the help, I've got my create script to generate the required
env vars as follows;

package require registry
registry set HKEY_CURRENT_USER\\Environment CHIP_$chip_name
$top_dir/$prj_name/$chip_name/$chp_issue

However, I can't seem to modify them or delete them using the
following;

package require registry
registry delete HKEY_CURRENT_USER\\Environment CHIP_$chip_name
registry set HKEY_CURRENT_USER\\Environment CHIP_$chip_name
$top_dir/$prj_name/$chip_name/$new_issue

I've tried with & without the registry delete command. I thought it
would just overwrite, it didn't so added the delete, still not working?

Any ideas please?

Pat Thoyts

2005-10-20, 7:00 pm

"Niv (KP)" <kev.parsons@mbda.co.uk> writes:

>Thanks for the help, I've got my create script to generate the required
>env vars as follows;
>
> package require registry
> registry set HKEY_CURRENT_USER\\Environment CHIP_$chip_name
>$top_dir/$prj_name/$chip_name/$chp_issue
>
>However, I can't seem to modify them or delete them using the
>following;
>
> package require registry
> registry delete HKEY_CURRENT_USER\\Environment CHIP_$chip_name
> registry set HKEY_CURRENT_USER\\Environment CHIP_$chip_name
>$top_dir/$prj_name/$chip_name/$new_issue
>
>I've tried with & without the registry delete command. I thought it
>would just overwrite, it didn't so added the delete, still not working?
>
>Any ideas please?


Works for me on WinXP -
package require registry
registry set HKEY_CURRENT_USER\\Environment CHIP_xxx 1
registry set HKEY_CURRENT_USER\\Environment CHIP_xxx 2

fire up regedit and take a look -- value is 2

--
Pat Thoyts http://www.patthoyts.tk/
To reply, rot13 the return address or read the X-Address header.
PGP fingerprint 2C 6E 98 07 2C 59 C8 97 10 CE 11 E6 04 E0 B9 DD
Niv (KP)

2005-10-21, 3:58 am

All sorted at last, thanks for all the help.

The problem I had was with the variable name; I had written with
$chip_name
and was trying to overwrite with $chp_name, a simple but hard to spot
error.
I've now changed all my scripts to use the same names throughout.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com