Skip to content

Commit

Permalink
Merge pull request coreybutler#459 from noelhibbard/installer-improvm…
Browse files Browse the repository at this point in the history
…ents

Installer improvements when alt creds are required for elevation
  • Loading branch information
coreybutler authored Feb 14, 2023
2 parents 3cc5d93 + a9294d8 commit 1216b37
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 39 deletions.
11 changes: 11 additions & 0 deletions bin/setuserenv.vbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Set WSHShell = CreateObject("WScript.Shell")
userpath = WSHShell.RegRead("HKCU\Environment\Path")
If InStr(userpath, "%NVM_HOME%") = False Then
userpath = userpath & ";%NVM_HOME%;"
End If
If InStr(userpath, "%NVM_SYMLINK%") = False Then
userpath = userpath & ";%NVM_SYMLINK%;"
End If

userpath = Replace(userpath, ";;", ";")
WSHShell.RegWrite "HKCU\Environment\Path", userpath
6 changes: 6 additions & 0 deletions bin/unsetuserenv.vbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Set WSHShell = CreateObject("WScript.Shell")
userpath = WSHShell.RegRead("HKCU\Environment\Path")
userpath = Replace(userpath, "%NVM_HOME%", "")
userpath = Replace(userpath, "%NVM_SYMLINK%", "")
userpath = Replace(userpath, ";;", ";")
WSHShell.RegWrite "HKCU\Environment\Path", userpath
49 changes: 10 additions & 39 deletions nvm.iss
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ var
procedure TakeControl(np: string; nv: string);
var
path: string;
ResultCode: integer;
begin
// Move the existing node.js installation directory to the nvm root & update the path
RenameFile(np,ExpandConstant('{app}')+'\'+nv);
Expand All @@ -103,15 +104,7 @@ begin
RegWriteExpandStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', path);
RegQueryStringValue(HKEY_CURRENT_USER,
'Environment',
'Path', path);
StringChangeEx(path,np+'\','',True);
StringChangeEx(path,np,'',True);
StringChangeEx(path,np+';;',';',True);
RegWriteExpandStringValue(HKEY_CURRENT_USER, 'Environment', 'Path', path);
ExecAsOriginalUser('wscript', 'setuserenv.vbs', ExpandConstant('{app}'), SW_HIDE, ewWaitUntilTerminated, ResultCode);
nodeInUse := ExpandConstant('{app}')+'\'+nv;
Expand Down Expand Up @@ -207,6 +200,7 @@ function InitializeUninstall(): Boolean;
var
path: string;
nvm_symlink: string;
ResultCode: integer;
begin
SuppressibleMsgBox('Removing NVM for Windows will remove the nvm command and all versions of node.js, including global npm modules.', mbInformation, MB_OK, IDOK);
Expand All @@ -223,12 +217,8 @@ begin
RegDeleteValue(HKEY_LOCAL_MACHINE,
'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
'NVM_SYMLINK')
RegDeleteValue(HKEY_CURRENT_USER,
'Environment',
'NVM_HOME')
RegDeleteValue(HKEY_CURRENT_USER,
'Environment',
'NVM_SYMLINK')
ExecAsOriginalUser('REG', 'DELETE HKCU\Environment /F /V NVM_HOME /D', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
ExecAsOriginalUser('REG', 'DELETE HKCU\Environment /F /V NVM_SYMLINK /D', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
RegQueryStringValue(HKEY_LOCAL_MACHINE,
'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
Expand All @@ -240,15 +230,7 @@ begin
RegWriteExpandStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', path);
RegQueryStringValue(HKEY_CURRENT_USER,
'Environment',
'Path', path);
StringChangeEx(path,'%NVM_HOME%','',True);
StringChangeEx(path,'%NVM_SYMLINK%','',True);
StringChangeEx(path,';;',';',True);
RegWriteExpandStringValue(HKEY_CURRENT_USER, 'Environment', 'Path', path);
ExecAsOriginalUser('wscript', 'unsetuserenv.vbs', ExpandConstant('{app}'), SW_HIDE, ewWaitUntilTerminated, ResultCode);
Result := True;
end;
Expand All @@ -257,6 +239,7 @@ end;
procedure CurStepChanged(CurStep: TSetupStep);
var
path: string;
ResultCode: Integer;
begin
if CurStep = ssPostInstall then
begin
Expand All @@ -265,8 +248,8 @@ begin
// Add Registry settings
RegWriteExpandStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'NVM_HOME', ExpandConstant('{app}'));
RegWriteExpandStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'NVM_SYMLINK', SymlinkPage.Values[0]);
RegWriteExpandStringValue(HKEY_CURRENT_USER, 'Environment', 'NVM_HOME', ExpandConstant('{app}'));
RegWriteExpandStringValue(HKEY_CURRENT_USER, 'Environment', 'NVM_SYMLINK', SymlinkPage.Values[0]);
ExecAsOriginalUser('REG', 'ADD HKCU\Environment /F /V NVM_HOME /D "' + ExpandConstant('{app}') + '"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
ExecAsOriginalUser('REG', 'ADD HKCU\Environment /F /V NVM_SYMLINK /D "' + SymlinkPage.Values[0] + '"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppId}_is1', 'DisplayVersion', '{#MyAppVersion}');
Expand All @@ -284,19 +267,7 @@ begin
StringChangeEx(path,';;',';',True);
RegWriteExpandStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', path);
end;
RegQueryStringValue(HKEY_CURRENT_USER,
'Environment',
'Path', path);
if Pos('%NVM_HOME%',path) = 0 then begin
path := path+';%NVM_HOME%';
StringChangeEx(path,';;',';',True);
RegWriteExpandStringValue(HKEY_CURRENT_USER, 'Environment', 'Path', path);
end;
if Pos('%NVM_SYMLINK%',path) = 0 then begin
path := path+';%NVM_SYMLINK%';
StringChangeEx(path,';;',';',True);
RegWriteExpandStringValue(HKEY_CURRENT_USER, 'Environment', 'Path', path);
end;
ExecAsOriginalUser('wscript', 'setuserenv.vbs', ExpandConstant('{app}'), SW_HIDE, ewWaitUntilTerminated, ResultCode);
end;
end;
Expand Down

0 comments on commit 1216b37

Please sign in to comment.