forked from yask123/Instant-Music-Downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.bat
64 lines (53 loc) · 1.68 KB
/
install.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
@echo off
cd %~dp0
rem Script goes to System32 if you start it as admin
echo This will copy Music-Downloader to %UserProfile%\music_downloader and set it in PATH.
goto check_Permissions
:back
mkdir "%UserProfile%\music_downloader"
copy ".\music_downloader.py" "%UserProfile%\music_downloader\music_downloader.py"
rem check if already exists in PATH
echo. ";%PATH%;" | findstr /C:";%UserProfile%\music_downloader;" 1>nul
if errorlevel 1 (
set svar="%PATH%;%UserProfile%\music_downloader;;"
goto strlen
:pathok
@setx PATH "%PATH%;%UserProfile%\music_downloader" /m
goto end
rem needed as if-else logic is lost after goto
) ELSE (
echo Already exists in PATH
)
:end
set /p tempvar="SUCCESS. Press Enter to continue"
exit /B
rem http://stackoverflow.com/a/11995662/2295672
:check_Permissions
echo Administrative permissions required. Detecting permissions...
net session >nul 2>&1
if %errorLevel% == 0 (
rem echo Success: Administrative permissions confirmed.
goto back
) else (
echo Failure: Try running as administrator
pause >nul
exit /B
)
rem http://stackoverflow.com/a/5841587/2295672
:strlen
rem setlocal EnableDelayedExpansion for changing var and using it in loop
setlocal EnableDelayedExpansion
set "s=!%svar%!#"
set "len=0"
for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
if "!s:~%%P,1!" NEQ "" (
set /a "len+=%%P"
set "s=!s:~%%P!"
)
)
if %len% GEQ 1024 (
set /p tempvar="PATH is more than 1024 characters. This can't be handled by the script. You will have to add that manually."
exit /b
) else (
goto pathok
)