Switching Environment Variables in XP
Switching Environment Variables in XP
Author
Discussion

sprintmp

Original Poster:

379 posts

314 months

Friday 13th January 2006
quotequote all
Morning all,

Here's a little one to tax those brain cells on a Friday.

I have a developer who wishes to run 2 different C compilers on the same PC. Unfortunatly both compilers use the same environment variables names, but need to point to differing paths etc.

One possible solution is to enable him to log in with a different username. However due to 'corporate' restrictions this is not possible. I've done a search using Google, but couldn't come up with anything.

Anybone any ideas?

Thanks

GregE240

10,857 posts

297 months

Friday 13th January 2006
quotequote all
Can't you just set up 2 batch files for him that sets the path variable to whatever he wants it to be?

sprintmp

Original Poster:

379 posts

314 months

Friday 13th January 2006
quotequote all
No that's not possible. There are actual same named variables that need differing parameters depending on which compiler he uses. If it could be done using a batch file that would be great.

Thanks for your input.

slinky

15,704 posts

279 months

Friday 13th January 2006
quotequote all
to set an enviroment variable you can simply use the "set" command..

A batch file (as suggested by Greg) using multiple set commands would most probably do the job..

HTH,

slinky

pdV6

16,442 posts

291 months

Friday 13th January 2006
quotequote all
What I think you can do is create a batch file that first sets the environment variables as required and then goes on to start the program that corresponds to the compiler (e.g. Visual Studio).

Then, create a desktop shortcut to the batch file for ease of use.

{eta:} I think you'll need to do it this way as otherwise the context that the compiler is running in won't have visibility of the (temporary) environment variables that the batch file sets up.

>> Edited by pdV6 on Friday 13th January 10:16

pentoman

4,835 posts

293 months

Friday 13th January 2006
quotequote all
Also worth bearing in mind:

If you have a command window open, and change the environment variables through windows, the command window will not recognize the changes and continue using the old ones.

So, (if you're using a cmd window) you could load a command window with one set of environment variables, change them, load another new one, and voila you have two sets of encironment variables.

I'm 90% sure this will work anyway...

Russell

sprintmp

Original Poster:

379 posts

314 months

Friday 13th January 2006
quotequote all
pdV6 said:


{eta:} I think you'll need to do it this way as otherwise the context that the compiler is running in won't have visibility of the (temporary) environment variables that the batch file sets up.

>> Edited by pdV6 on Friday 13th January 10:16


So would that be why when I used SET from the command line, and then looked in My computer/Properties/Advanced/environment Variables it did not show a test variable that I set up? However, when I did a set (on it's own) the variable was there. It must be a context thing?

pdV6

16,442 posts

291 months

Friday 13th January 2006
quotequote all
I think so. Try the batch file approach and see...

sprintmp

Original Poster:

379 posts

314 months

Friday 13th January 2006
quotequote all
Thanks I'll give it a go.

P

pmanson

13,388 posts

283 months

Friday 13th January 2006
quotequote all
VirtualPC?

Set up 2 different environments on the same PC which are exactly the same then run the C commands in either one.

And you can use the same login in both environments


>> Edited by pmanson on Friday 13th January 10:47

victormeldrew

8,293 posts

307 months

Friday 13th January 2006
quotequote all
pmanson said:
VirtualPC?

Set up 2 different environments on the same PC which are exactly the same then run the C commands in either one.

And you can use the same login in both environments
That would get my vote - I use VMWare Workstation to do that sort of thing.

_deejay_

5,057 posts

284 months

Friday 13th January 2006
quotequote all
No to run a compiler surely? An easy way to kill the performance of the machine if you ask me.
I'd stick with the batch file approach

dilbert

7,741 posts

261 months

Friday 13th January 2006
quotequote all
If he's a developer worth having, then he'll just spend the three minutes it takes to write a short program that can run as a tool in the development environment, that adjusts the environment variable;

WIN32API Reference said:

The SetEnvironmentVariable function sets the value of an environment variable for the current process.

BOOL SetEnvironmentVariable(
LPCTSTR lpName, // address of environment variable name
LPCTSTR lpValue // address of new value for variable
);

Parameters;

lpName
Pointer to a null-terminated string that specifies the environment variable whose value is being set. The operating system creates the environment variable if it does not exist and lpValue is not NULL.

lpValue
Pointer to a null-terminated string containing the new value of the specified environment variable. If this parameter is NULL, the variable is deleted from the current process's environment.

Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winbase.h.
Import Library: Use kernel32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.


annodomini2

6,971 posts

281 months

Friday 13th January 2006
quotequote all
Surely you could do this from the make file? Assuming you're using make?

>> Edited by annodomini2 on Friday 13th January 15:37

dilbert

7,741 posts

261 months

Friday 13th January 2006
quotequote all
annodomini2 said:
Surely you could do this from the make file? Assuming you're using make?

>> Edited by annodomini2 on Friday 13th January 15:37


Probably can.
Most people these days don't have a clue if you ask them to deal with the linker directly. Most people (me included) have forgotten that you used to have to compile assemble link and make!


Edited to add;

You only get a job these days, if you know ASP and VB!


>> Edited by dilbert on Friday 13th January 15:43

GreenV8S

31,024 posts

314 months

Friday 13th January 2006
quotequote all
sprintmp said:

I have a developer who wishes to run 2 different C compilers on the same PC. Unfortunatly both compilers use the same environment variables names, but need to point to differing paths etc.


I don't see any reason to consider multiple logins, virtual PCs etc. This is massive overkill for what should be a trivial problem.

How does your developer invoke the compiler - command line, GUI etc?

annodomini2

6,971 posts

281 months

Friday 13th January 2006
quotequote all
dilbert said:


You only get a job these days, if you know ASP and VB!


>> Edited by dilbert on Friday 13th January 15:43


Depends what you want to work on, anyone can do VB or ASP!

Embedded control systems in various languages makes for a more intersting challenge IMHO.

sprintmp

Original Poster:

379 posts

314 months

Monday 16th January 2006
quotequote all
Thanks guys for all the input.

The guy is good, but mainly uses Linux. I must admit, if I'd have thought about it a little more , I'd have gone for the batch file option. Unfortunatly we had another crisis on at the time....

So who remembers LDX, Move, SRC, SLC etc? Or even #XQMY (for 'scratching' tapes). There is a bit of history here http://en.wikipedia.org/wiki/ICT_1900 including a link for a George 3 emulator to run on PCs, Solaris & Linux. Also here www.fcs.eu.com/index.html (which has loads of stuff) - ah! those were the days!