Nvm
This Package installs the node version manager developed by Corey Butler on Github (https://github.com/coreybutler/nvm-windows), for this Package i used the noinstall Version and created the Settings.txt with these contents:
root: C:\opt\nvm path: C:\opt\nodejs arch: 64 proxy: none
You will have to set the root and the copy paths in the package to where you want to install the nvm. The path variable points to where nvm creates the Link it uses to switch between different node versions.
XML
<package id="nvm" name="nvm" revision="12" priority="0" reboot="false" >
<variable name="version" value="1.1.0" />
<check type="file" condition="exists" path="C:\opt\nvm\%version%.txt" />
<install cmd='%COMSPEC% /c echo %path%>C:\path.txt'></install-->
<install cmd='%COMSPEC% /c SETX path "C:\opt\nvm;C:\opt\nodejs;%path%" /M'></install>
<install cmd='%COMSPEC% /c SETX NVM_HOME "C:\opt\nvm" /M'></install>
<install cmd='%COMSPEC% /c SETX NVM_SYMLINK "C:\opt\nodejs" /M'></install>
<install cmd='%COMSPEC% /c robocopy %SOFTWARE%\node\nvm%version% C:\opt\nvm>NUL'><exit code="1" /></install>
<install cmd='%COMSPEC% /c robocopy C:\opt\nvm C:\ settings.txt>NUL'><exit code="1" /></install>
<upgrade cmd='%COMSPEC% /c robocopy /e %SOFTWARE%\node\nvm%version% C:\opt\nvm %version%.txt>NUL'><exit code="1" /><exit code="2" /><exit code="3" /></upgrade>
<upgrade cmd='%COMSPEC% /c robocopy /e %SOFTWARE%\node\nvm%version% C:\opt\nvm elevate.cmd>NUL'><exit code="1" /><exit code="2" /><exit code="3" /></upgrade>
<upgrade cmd='%COMSPEC% /c robocopy /e %SOFTWARE%\node\nvm%version% C:\opt\nvm elevate.vbs>NUL'><exit code="1" /><exit code="2" /><exit code="3" /></upgrade>
<upgrade cmd='%COMSPEC% /c robocopy /e %SOFTWARE%\node\nvm%version% C:\opt\nvm LICENSE>NUL'><exit code="1" /><exit code="2" /><exit code="3" /></upgrade>
<upgrade cmd='%COMSPEC% /c robocopy /e %SOFTWARE%\node\nvm%version% C:\opt\nvm nvm.exe>NUL'><exit code="1" /><exit code="2" /><exit code="3" /></upgrade>
<upgrade cmd='%COMSPEC% /c robocopy /e %SOFTWARE%\node\nvm%version% C:\opt\nvm settings.txts>NUL'><exit code="1" /><exit code="2" /><exit code="3" /></upgrade>
<upgrade cmd='%COMSPEC% /c robocopy C:\opt\nvm C:\ settings.txt>NUL'><exit code="1" /><exit code="3" /></upgrade>
<upgrade cmd='%COMSPEC% /c del C:\opt\nvm\%oldversion%.txt'></upgrade>
<remove cmd='rmdir /S /Q C:\opt\nvm' ><exit code="0" /><exit code="128" /><exit code="-1073741515" /></remove>
<remove cmd='rmdir /S /Q C:\opt\nodejs'><exit code="0" /><exit code="128" /><exit code="-1073741515" /></remove>
<remove cmd='rmdir /S /Q C:\settings.txt'><exit code="0" /><exit code="128" /><exit code="-1073741515" /></remove>
</package>
After installation of the Package it is necessary to reboot the Computer or use this Powershell script which forces Windows to reread all System environment Variables because the SETX does not work exactly as intended with WPKG:
Powershell
if (-not ("win32.nativemethods" -as [type])) {
# import sendmessagetimeout from win32
add-type -Namespace Win32 -Name NativeMethods -MemberDefinition @"
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam, uint fuFlags, uint uTimeout, out UIntPtr lpdwResult);
"@
}
$HWND_BROADCAST = [intptr]0xffff;
$WM_SETTINGCHANGE = 0x1a;
$result = [uintptr]::zero
# notify all windows of environment block change
[win32.nativemethods]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE,
[uintptr]::Zero, "Environment", 2, 5000, [ref]$result);
Whenever i tried to execute this Script with wpkg it would go into a endless loop and i had to force quit powershell to continue, maybe someone knows a way to achieve this so this can be used without needing a reboot