Skip to content

Instantly share code, notes, and snippets.

@azalea
Created December 8, 2016 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azalea/212fa179b9c7905d5a939b4ea889302c to your computer and use it in GitHub Desktop.
Save azalea/212fa179b9c7905d5a939b4ea889302c to your computer and use it in GitHub Desktop.
!macro ProcessEnvPrependPath UN
;; ref: http://stackoverflow.com/a/32384667/1292238
!ifndef ERROR_ENVVAR_NOT_FOUND
!define ERROR_ENVVAR_NOT_FOUND 203
!endif
!if "${NSIS_PTR_SIZE}" <= 4
!include LogicLib.nsh
Function ${UN}ProcessEnvPrependPath ; IN:Path OUT:N/A
System::Store S
Pop $1
System::Call 'KERNEL32::GetEnvironmentVariable(t "PATH", t, i0)i.r0'
${If} $0 = 0
System::Call 'KERNEL32::SetEnvironmentVariable(t "PATH", tr1)'
${Else}
StrLen $2 $1
System::Call '*(&t$2,&t1,&t$0)i.r9'
StrCpy $3 '$1;'
System::Call 'KERNEL32::lstrcat(ir9, tr3)'
System::Call '*(&t$0)i.r8'
System::Call 'KERNEL32::GetEnvironmentVariable(t "PATH", ir8, ir0)i.r0'
System::Call 'KERNEL32::lstrcat(ir9, ir8)'
System::Call 'KERNEL32::SetEnvironmentVariable(t "PATH", ir9)'
System::Free $9
${EndIf}
System::Store L
FunctionEnd
!endif
!macroend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment