HartWoom
HartWoom

Reputation: 587

Modify Environment Variable Path for local machine with nsis

I'm trying to edit the Local Machine Environment Variable Path with an NSIS script. I've found this interesting post but I haven't been able to "install", if I may say, the alternative build of NSIS they've been talking about in the first answer.

I did try things like this post but without success.

BUT I've managed to use the script from Anders's answer on the same question asked here The thing is, it only modify the Path Environment table for the current user, and I want to modify it for the local machine.

I've tried to modify the variable here :

Push ${HKEY_CURRENT_USER}

to :

Push ${HKEY_LOCAL_MACHINE}

but it seems to be not enough because I keep getting an error 87.

So my questions are: Is it possible from Anders's script to modify Environment Variable for the Local Machine ? And if yes, how ?

Best regards, Antoine.

Upvotes: 0

Views: 905

Answers (1)

Anders
Anders

Reputation: 101569

The key used by HKLM is also different but once you give it the correct key it works for me:

!include LogicLib.nsh
!include WinCore.nsh
!ifndef NSIS_CHAR_SIZE
!define NSIS_CHAR_SIZE 1
!endif
!ifndef HKEY_LOCAL_MACHINE
!error HKEY_LOCAL_MACHINE
!endif

Function RegAppendString
TODO: Function from https://stackoverflow.com/a/31342128/3501# goes here
FunctionEnd

RequestExecutionLevel Admin ; Request UAC elevation

Section

Push ${HKEY_LOCAL_MACHINE}
Push "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
Push "Path"
Push ";"
Push "c:\whatever"
Call RegAppendString
Pop $0
DetailPrint RegAppendString:Error=$0

SectionEnd 

but things have moved on since that function was posted and there is now a plug-in specifically created for environment variable manipulation. I would recommend that you try the EnVar plug-in.

Upvotes: 1

Related Questions