Archive: Problems with Setting Environment Variables


Problems with Setting Environment Variables
I will set few new enviroment variables, i got the source from HERE
My source is

!include "MUI.nsh"
!include "WriteEnvStr.nsh"
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "logo_fzk_1.bmp"
!define MUI_ABORTWARNING
!define ALL_USERS
;!define MUI_FINISHPAGE
;!define MUI_FINISHPAGE_NOAUTOCLOSE

Name "AAA"
OutFile "AAA.exe"
InstallDir "C:\"

!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
;!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_LANGUAGE "GERMAN"

Section
SetOutPath $INSTDIR\

File /r Embedded
SectionEnd

Section "Add Env Var"
Push BBB
Push BBB
Call WriteEnvStr
SectionEnd

Function .onInstSuccess
MessageBox MB_OK "BLA"
REBOOT
FunctionEnd

And that´s the error message i get:

Processed 1 file, writing output:
Adding plug-ins initializing function... Done!
warning: Uninstall section found but WriteUninstaller never used - no uninstaller will be created.
Error: resolving install function "IsNT" in function "WriteEnvStr"
Note: uninstall functions must begin with "un.", and install functions must not
Error - aborting creation process


Make sure you copy all the code into WriteEnvStr.nsh. Not just the Function WriteEnvStr bit.

-Stu


files needed
Where can i get WriteEnvStr.nsh??


My Script

Section "Add Env Var"
Push "HOMEDIR"
Push "C:\New Home Dir\"
Call WriteEnvStr
SectionEnd

My WriteEnvStr.nsh

!include WinMessages.nsh

!ifdef ALL_USERS
!define WriteEnvStr_RegKey \
'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
!else
!define WriteEnvStr_RegKey 'HKCU "Environment"'
!endif

#
# WriteEnvStr - Writes an environment variable
# Note: Win9x systems requires reboot
#
# Example:
# Push "HOMEDIR" # name
# Push "C:\New Home Dir\" # value
# Call WriteEnvStr
#
Function WriteEnvStr
Exch $1 ; $1 has environment variable value
Exch
Exch $0 ; $0 has environment variable name
Push $2

Call IsNT
Pop $2
StrCmp $2 1 WriteEnvStr_NT
; Not on NT
StrCpy $2 $WINDIR 2 ; Copy drive of windows (c:)
FileOpen $2 "$2\autoexec.bat" a
FileSeek $2 0 END
FileWrite $2 "$\r$\nSET $0=$1$\r$\n"
FileClose $2
SetRebootFlag true
Goto WriteEnvStr_done

WriteEnvStr_NT:
WriteRegExpandStr ${WriteEnvStr_RegKey} $0 $1
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} \
0 "STR:Environment" /TIMEOUT=5000

WriteEnvStr_done:
Pop $2
Pop $1
Pop $0
FunctionEnd

#
# un.DeleteEnvStr - Removes an environment variable
# Note: Win9x systems requires reboot
#
# Example:
# Push "HOMEDIR" # name
# Call un.DeleteEnvStr
#
Function un.DeleteEnvStr
Exch $0 ; $0 now has the name of the variable
Push $1
Push $2
Push $3
Push $4
Push $5

Call un.IsNT
Pop $1
StrCmp $1 1 DeleteEnvStr_NT
; Not on NT
StrCpy $1 $WINDIR 2
FileOpen $1 "$1\autoexec.bat" r
GetTempFileName $4
FileOpen $2 $4 w
StrCpy $0 "SET $0="
SetRebootFlag true

DeleteEnvStr_dosLoop:
FileRead $1 $3
StrLen $5 $0
StrCpy $5 $3 $5
StrCmp $5 $0 DeleteEnvStr_dosLoop
StrCmp $5 "" DeleteEnvStr_dosLoopEnd
FileWrite $2 $3
Goto DeleteEnvStr_dosLoop

DeleteEnvStr_dosLoopEnd:
FileClose $2
FileClose $1
StrCpy $1 $WINDIR 2
Delete "$1\autoexec.bat"
CopyFiles /SILENT $4 "$1\autoexec.bat"
Delete $4
Goto DeleteEnvStr_done

DeleteEnvStr_NT:
DeleteRegValue ${WriteEnvStr_RegKey} $0
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} \
0 "STR:Environment" /TIMEOUT=5000

DeleteEnvStr_done:
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
FunctionEnd

My Error Message

Processed 1 file, writing output:
Adding plug-ins initializing function... Done!
Error: resolving install function "WriteEnvStr" in install section "Add Env Var" (1)
Note: uninstall functions must begin with "un.", and install functions must not
Error - aborting creation process
Compilation time: 1.249 sec.


I´ve found the right version of the WriteEnvStr.nsh so now it works, but i still got a warning:

1 warning:
Uninstall section found but WriteUninstaller never used - no uninstaller will be created.

But now i also have read an Enviroment Variable, maybe someone can help me.