Skip to content

Commit

Permalink
Try to run commands before elevating them. Not tested and I have neve…
Browse files Browse the repository at this point in the history
…r touched golang. Checking required to test on a different pc.
  • Loading branch information
steam committed Jun 24, 2019
1 parent 5988853 commit 7cde75d
Show file tree
Hide file tree
Showing 15 changed files with 438 additions and 333 deletions.
18 changes: 17 additions & 1 deletion .gitattributes
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
5 changes: 5 additions & 0 deletions bin/elevate.cmd
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" %*
13 changes: 13 additions & 0 deletions bin/elevate.vbs
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
67 changes: 57 additions & 10 deletions bin/install.cmd
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
7 changes: 7 additions & 0 deletions bin/tryelevate.cmd
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" %*
13 changes: 13 additions & 0 deletions bin/tryelevate.vbs
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 modified buildtools/ISCmplr.dll
Binary file not shown.
Binary file modified buildtools/ISPP.dll
Binary file not shown.
Binary file modified buildtools/Setup.e32
Binary file not shown.
Binary file modified buildtools/SetupLdr.e32
Binary file not shown.
Binary file modified buildtools/iscc.exe
Binary file not shown.
Binary file modified buildtools/islzma.dll
Binary file not shown.
Binary file modified buildtools/zip.exe
Binary file not shown.

0 comments on commit 7cde75d

Please sign in to comment.