forked from chawyehsu/nvm-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try to run commands before elevating them. Not tested and I have neve…
…r touched golang. Checking required to test on a different pc.
- Loading branch information
steam
committed
Jun 24, 2019
1 parent
5988853
commit 7cde75d
Showing
15 changed files
with
438 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,17 @@ | ||
* text eol=lf | ||
* text eol=crlf | ||
|
||
# Denote files as text files. | ||
*.go text | ||
*.cmd text | ||
*.bat text | ||
*.batch txt | ||
*.vbs txt | ||
*.vb txt | ||
|
||
.gitattributes text eol=crlf | ||
|
||
# Denote all files that are truly binary and should not be modified. | ||
*.dll | ||
*.exe | ||
*.e32 | ||
*.iss |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@setlocal | ||
@echo off | ||
set CMD=%* | ||
set APP=%1 | ||
start wscript //nologo "%~dpn0.vbs" %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Set Shell = CreateObject("Shell.Application") | ||
Set WShell = WScript.CreateObject("WScript.Shell") | ||
Set ProcEnv = WShell.Environment("PROCESS") | ||
|
||
cmd = ProcEnv("CMD") | ||
app = ProcEnv("APP") | ||
args= Right(cmd,(Len(cmd)-Len(app))) | ||
|
||
If (WScript.Arguments.Count >= 1) Then | ||
Shell.ShellExecute app, args, "", "runas", 0 | ||
Else | ||
WScript.Quit | ||
End If |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,67 @@ | ||
@echo off | ||
set /P NVM_PATH="Enter the absolute path where the zip file is extracted/copied to: " | ||
@ECHO OFF & CLS & ECHO. | ||
|
||
IF "%1"=="" ( | ||
set /P NVM_PATH="Enter the absolute path where the zip file is extracted/copied to: " | ||
) ELSE ( | ||
set NVM_PATH=%1 | ||
) | ||
mkdir %NVM_PATH% && echo "%NVM_PATH% was created!" || echo "%NVM_PATH% was unable to be created." | ||
|
||
set DRIVE=%NVM_PATH:~0,2% | ||
IF "%DRIVE:~1,1%"==":" ( | ||
%DRIVE% | ||
) | ||
|
||
REM Sets PROGRAMS directory as NVM_PATH parent directory | ||
REM Example: "C:\Programs" from "C:\Programs\nvm" (if %NVM_PATH% is equal to "C:\Programs\nvm") | ||
REM | ||
SET CURRENTDIR=%CD% | ||
CD %NVM_PATH% | ||
CD .. | ||
SET PROGRAMS=%CD% | ||
CD %CURRENTDIR% | ||
|
||
REM Check if running with admin rights (https://stackoverflow.com/a/12264592/458321) | ||
NET FILE 1>NUL 2>NUL & IF ERRORLEVEL 1 (set ISADMIN=1) | ||
|
||
IF "%ISADMIN%"=="1" ( | ||
GOTO ADMIN | ||
) ELSE ( | ||
GOTO NONADMIN | ||
) | ||
|
||
:ADMIN | ||
REM Set environment variables to machine level (admin rights required) | ||
set SETENVVAR=set /M | ||
GOTO FINISH | ||
:NONADMIN | ||
echo "Check if nvm path requires admin writes to create file" > %NVM_PATH%\checkpermissions.txt || elevate.cmd install.cmd %NVM_PATH% | ||
REM Set environment variables to local user (no admin rights required) | ||
set SETENVVAR=set | ||
:FINISH | ||
|
||
%SETENVVAR% NVM_PATH=%NVM_PATH% | ||
|
||
set NVM_HOME=%NVM_PATH% | ||
set NVM_SYMLINK=C:\Program Files\nodejs | ||
setx /M NVM_HOME "%NVM_HOME%" | ||
setx /M NVM_SYMLINK "%NVM_SYMLINK%" | ||
%SETENVVAR% NVM_HOME=%NVM_PATH% | ||
|
||
set NVM_SYMLINK=%PROGRAMS%\nodejs | ||
%SETENVVAR% NVM_SYMLINK=%PROGRAMS%\nodejs | ||
|
||
for /f "skip=2 tokens=2,*" %%A in ('reg query "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v Path 2^>nul') do ( | ||
setx /M PATH "%%B;%%NVM_HOME%%;%%NVM_SYMLINK%%" | ||
IF "%ISADMIN%"=="1" ( | ||
for /f "skip=2 tokens=2,*" %%A in ('reg query "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v Path 2^>nul') do ( | ||
%SETENVVAR% PATH "%%B;%%NVM_HOME%%;%%NVM_SYMLINK%%" | ||
) | ||
) ELSE ( | ||
echo.%PATH%|findstr /C:"%NVM_PATH%" >nul 2>&1 || %SETENVVAR% PATH=%PATH%;%NVM_PATH% | ||
) | ||
|
||
if exist "%SYSTEMDRIVE%\Program Files (x86)\" ( | ||
set SYS_ARCH=64 | ||
set SYS_ARCH=64 | ||
) else ( | ||
set SYS_ARCH=32 | ||
set SYS_ARCH=32 | ||
) | ||
(echo root: %NVM_HOME% && echo path: %NVM_SYMLINK% && echo arch: %SYS_ARCH% && echo proxy: none) > %NVM_HOME%\settings.txt | ||
|
||
notepad %NVM_HOME%\settings.txt | ||
start "" %NVM_HOME%\settings.txt || explorer %NVM_HOME%\settings.txt || notepad %NVM_HOME%\settings.txt | ||
@echo on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@setlocal | ||
@echo off | ||
set CMD=%* | ||
set APP=%1 | ||
|
||
REM tries to run any script passed first without admin rights | ||
%* || start wscript //nologo "%~dpn0.vbs" %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Set Shell = CreateObject("Shell.Application") | ||
Set WShell = WScript.CreateObject("WScript.Shell") | ||
Set ProcEnv = WShell.Environment("PROCESS") | ||
|
||
cmd = ProcEnv("CMD") | ||
app = ProcEnv("APP") | ||
args= Right(cmd,(Len(cmd)-Len(app))) | ||
|
||
If (WScript.Arguments.Count >= 1) Then | ||
Shell.ShellExecute app, args, "", "runas", 0 | ||
Else | ||
WScript.Quit | ||
End If |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.