Archive: Why no WriteEnvStr instruction ?


Why no WriteEnvStr instruction ?
I tried to read and write environment variables (under Windows NT 4) with NSIS (I use the 1.99).
I found the instruction ReadEnvStr to read them, and it works very well. But there is no instruction to write it directly. :cry:

So I used WriteRegStr to set directly the variables in the Windows registry (HKCU/Environment). But Windows does not care about the changes. I have to go to the Windows environment variables dialog, then select OK to make it work. Rebooting the computer work too. But both of the solutions are not convenient... :(

Is there a way to write an environment variable and make it work with NSIS ? :D


Have a look here. This script should help you understand how to do it.


Thank's a lot. It works well !

But it's boring to write code for both Windows 9x (or ME) and NT. I'll see if I can write a function to do that...

Let's sum up:
For Windows 95 or ME, to change environment variables, you have to modify autoexec.bat
For Windows NT, just modify it into the registry


Yep, that's how it works... But why rewrite? Just copy my code and change "Path" to whatever variable you want to set, or better yet, make it a function variable (using the stack). Don't forget to call RefreshEnv.exe on NT so you won't have to reboot.


Hi,

While the code is quite good (and I know given the language it took a lot of work and probably swearing) it only handles the "PATH" environment variable.

I too would like some code for this...

I need to update the PATH, some PATH like environment variables and also simpler environment variables (set text). This sort of stuff should really be in the NSIS EXE.

Bye,
Dennis


Why should it be in the EXE if you can do it with the script? It is not that complicated...


Originally posted by kichik
Why should it be in the EXE if you can do it with the script? It is not that complicated...
Hi,

For something thats not that complicated there seems to be a severe lack of code to be downloaded, and not just in this area...

I could do it but there is just too few hours in the day to do everything...

My 2 cents worth,
Dennis

Severe lack? It does exactly what you want! All you have to do is to change "PATH" to whatever you want it to be or make it a pushed argument to the function... Do you want me to write it?


Hmm

Originally posted by dbareis This sort of stuff should really be in the NSIS EXE.
That's like saying that in the C language the input/output instructions should be part of the language. However, they're not, they're something implemented in C that you can "include". Surely you can put KiCHiK's stuff into functions/macros in NSIS in a .nsh file or whatever and "include" them and hey voila you have a similar solution to that in C and no need for bloating the compiler.

Here it is, enjoy :D

[edit]Attachment removed. Newer version below.[/edit]


I meant I my first post, to write a function that accept as arguments:
- the environment variable to consider
- the action to do on it (ie: delete or write new value)
and the function would do everything needed for Windows 9x and NT OS.

Indeed, that's not very complicated from your sources...


kichik y think there is an error in your code but i'm not sure:

In function WriteEnvStr:


StrCpy $2 $WINDIR 2 ; Copy drive of windows (c:)
FileOpen $2 "$1\autoexec.bat" a


should be


StrCpy $2 $WINDIR 2 ; Copy drive of windows (c:)
FileOpen $2 "$2\autoexec.bat" a
^

Indeed. Thank you.


Did you update the SourceForge thingie? I'd check by myself by I can't be arsed to do so with this Dial-up plus I'm about to go to the Air-port. (ITALY! WEE!)

See ya' next week kichik. :)


What does this script has to do with SourceForge CVS?

Have fun in Italy :D


Exactly what I was looking for, thanks very much Kichik :)