- NSIS Discussion
- SetSystemEnvironmentVariable
Archive: SetSystemEnvironmentVariable
shortpasta
1st June 2003 23:29 UTC
SetSystemEnvironmentVariable
the application i install runs as a service.
because of this i need to set a SYSTEM environment variable and update the SYSTEM path. can anyone tell me how to do this?
the samples i found on the forums/sf.net only work on the USER environment.
PS: the only way i could find to set system environment variables is with microsoft's "setx.exe" utility (from their resource kit).
PS2: i also know that there is are "Get/SetSystemEnvironmentVariable" functions in the SDK but don't know which module.
kichik
1st June 2003 23:35 UTC
Welcome to the forum.
Use these functions:
http://nsis.sourceforge.net/archive/...php?pageid=137
When you define ALL_USERS they will affect the system environment variable table and not just the user's.
shortpasta
2nd June 2003 01:07 UTC
Thanks, it worked like you said.
i had seen that before but i immediately discarted it in my mind because it said ALL USERS and not SYSTEM account.
i looked further in microsoft's site & found out that the system environment functions are *deprecated*, odd to see microsoft do this, but it speaks in favor of the "ALL USERS" concept including SYSTEM.
Later gaters!
dabneyra
1st November 2003 04:33 UTC
WriteEnvStr.nsh
I cannot get this to work. Here is the relevant code:
!define ALL_USERS
!include WriteEnvStr.nsh
Section "Add Env Var"
Push Path
Push $INSTDIR\bin\win32
Call WriteEnvStr
SectionEnd
When I compile, I get this error ouput:
GetTempFileName -> $2
File: "RefreshEnv\Release\RefreshEnv.exe" -> no files found.
Usage: File [/nonfatal] [/a] ([/r] filespec [...]|/oname=outfile one_file_only)
!include: error in script: "C:\Program Files\NSIS\Include\WriteEnvStr.nsh" on line 52
I am sure I am just misunderstanding how to use this function. Can someone please set me straight? Thank you,
dabneyra
kichik
1st November 2003 14:45 UTC
You are using an old version of the function. Where did you take it from?
You shold update to the latest code from the link above.
dabneyra
2nd November 2003 05:10 UTC
WriteEnvStr update
Hi,
I think that old version was in the NSIS install. Anyway, I was able to compile with the new version using the same code as above. This time, it seems to have worked TOO well... instead of adding the install directory to the Path variable, it ENTIRELY replaced the Path directory with the install directory. The rest of my old path had been deleted. What to do? Is there some way to recover the default Windows XP Path? Sorry to continue being a pain in the ass about this, but I would really like to understand how this is working. Thanks,
dabneyra
kichik
2nd November 2003 07:28 UTC
Isn't that what you've wanted? You've used WriteEnvStr... WriteEnvStr replaces, it doesn't add. If you want to change the path you should use the path manipulation functions.
As for restoring, try system restore.
dabneyra
2nd November 2003 17:15 UTC
Change Path for all users
Hi,
I saw those functions earlier, and actually was able to use them to append to the user path variable, but not the system path variable. It was not immediately obvious to me how to use or modify the path manipulation functions to set the path for all users.
Thanks,
dabneyra
dabneyra
2nd November 2003 20:28 UTC
Found it!
Hi,
this thread had the answer I was looking for. Briefly, in case someone in the future is looking at this message to try and solve this problem, the change to be made is as follows:
In the Path Manipulation Function, change
HKCU
to:
HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
Thanks for the help,
dabneyra