-
Notifications
You must be signed in to change notification settings - Fork 0
/
Revised-AdminLaunchOption.bat
361 lines (321 loc) · 12.8 KB
/
Revised-AdminLaunchOption.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
@echo off
setlocal enabledelayedexpansion
cls
set LOGFILE=%~dp0\install-log.txt
echo %date% %time% - Script started > %LOGFILE%
:: Check if running as administrator and, if not, elevate permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges... >> %LOGFILE%
goto UACPrompt
) else (
echo Running with administrative privileges... >> %LOGFILE%
goto gotAdmin
)
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" (
del "%temp%\getadmin.vbs"
)
pushd "%CD%"
CD /D "%~dp0"
:: Create the C:\NexTool directory
if not exist "C:\NexTool\" (
mkdir "C:\NexTool"
)
:: Set full permissions for the directory
icacls "C:\NexTool" /grant Everyone:F /T /C /Q
if "%errorlevel%" NEQ "0" (
echo %date% %time% - Error setting permissions for C:\NexTool >> %LOGFILE%
echo Failed to set permissions for C:\NexTool.
pause
exit /B
)
cd /D "C:\NexTool"
:: Check and Install Chocolatey
echo %date% %time% - Checking Chocolatey installation >> %LOGFILE%
choco --version > nul 2>&1
if errorlevel 1 (
echo Chocolatey not detected. Attempting installation... >> %LOGFILE%
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex (((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
FOR /F "tokens=*" %%i in ('choco --version') do set CHOCO_VERSION=%%i
IF NOT DEFINED CHOCO_VERSION (
echo %date% %time% - Error: Failed to install Chocolatey! >> %LOGFILE%
exit /B
) ELSE (
echo Chocolatey version: %CHOCO_VERSION% >> %LOGFILE%
)
) ELSE (
FOR /F "tokens=*" %%i in ('choco --version') do set CHOCO_VERSION=%%i
echo Chocolatey version: %CHOCO_VERSION% already installed >> %LOGFILE%
)
:: Check Windows version
for /f "tokens=4-5 delims=. " %%a in ('ver') do (
set major=%%a
set minor=%%b
)
if !major! LSS 10 (
echo Winget is only available for Windows 10 and later. Continuing on with script. >> %LOGFILE%
pause
goto CheckAria2c
)
:CheckWinget
echo %date% %time% - Checking Winget installation >> %LOGFILE%
winget --version > nul 2>&1
if errorlevel 1 (
echo Winget not detected. Attempting installation... >> %LOGFILE%
echo Installing Winget... >> %LOGFILE%
choco install winget -y -n
if errorlevel 1 (
echo Error: Failed to install Winget >> %LOGFILE%
echo Please install Winget manually. >> %LOGFILE%
exit /B
)
) ELSE (
echo Winget is already installed. Checking for updates... >> %LOGFILE%
choco upgrade winget -y
)
:: Check and Install aria2c
:CheckAria2c
echo %date% %time% - Checking aria2c installation >> %LOGFILE%
FOR /F "tokens=3" %%i in ('aria2c --version ^| findstr "aria2 version"') do set ARIA2C_VERSION=%%i
IF NOT DEFINED ARIA2C_VERSION (
echo aria2c not detected. Installing... >> %LOGFILE%
choco install aria2 -y -n
) ELSE (
echo aria2c version: %ARIA2C_VERSION% already installed >> %LOGFILE%
)
:: Check and Install PowerShell Core
:CheckPowershellCore
echo %date% %time% - Checking PowerShell Core installation >> %LOGFILE%
FOR /F "delims=" %%i in ('pwsh --version 2^>^&1') do set POWERSHELLCORE_VERSION=%%i
IF NOT DEFINED POWERSHELLCORE_VERSION (
echo PowerShell Core not detected. Installing... >> %LOGFILE%
choco install powershell-core -y -n
) ELSE (
echo PowerShell Core version: %POWERSHELLCORE_VERSION% already installed >> %LOGFILE%
choco upgrade powershell-core -y -n
)
cls && goto CheckforPython3.11
:CheckforPython3.11
echo Checking for Python in PATH... >> %LOGFILE%
set python_path=C:\Python311\python.exe
if exist "!python_path!" (
echo Found !python_path! >> %LOGFILE%
"!python_path!" --version >> %LOGFILE%
goto Beginactualscriptcommands
) else (
echo Python 3.11.6 not found at expected location. >> %LOGFILE%
goto DownloadPython
)
:DownloadPython
setlocal
echo %date% %time% - Attempting download using aria2... >> %LOGFILE%
aria2c.exe --disable-ipv6 -x 4 -o "python-3.11.6-amd64.exe" -d "C:\NexTool" --allow-overwrite=true "https://www.python.org/ftp/python/3.11.6/python-3.11.6-amd64.exe"
if "%errorlevel%"=="0" (
echo %date% %time% - Downloaded successfully with aria2 >> %LOGFILE%
endlocal && set "DOWNLOAD_RESULT=0"
goto InstallPython
) else (
echo %date% %time% - Failed to download with aria2. Trying PowerShell... >> %LOGFILE%
powershell.exe pwsh -Command "Invoke-WebRequest -Uri 'https://www.python.org/ftp/python/3.11.6/python-3.11.6-amd64.exe' -OutFile 'C:\NexTool\python-3.11.6-amd64.exe'"
if "%errorlevel%"=="0" (
echo %date% %time% - Downloaded successfully with PowerShell >> %LOGFILE%
endlocal && set "DOWNLOAD_RESULT=0"
goto InstallPython
) else (
echo %date% %time% - Download failed with both methods >> %LOGFILE%
endlocal && set "DOWNLOAD_RESULT=1"
goto PythonDownloadCheck
)
)
:InstallPython
echo %date% %time% - Installing Python 3.11.6... >> %LOGFILE%
C:\NexTool\python-3.11.6-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 TargetDir=C:\Python311
if "%errorlevel%"=="0" (
echo %date% %time% - Python 3.11.6 installed successfully >> %LOGFILE%
goto CheckforPython3.11
) else (
echo %date% %time% - Failed to install Python 3.11.6. Aborting... >> %LOGFILE%
goto PythonDownloadCheck
)
:PythonDownloadCheck
set PYTHON_INSTALLER_PATH=C:\NexTool\python-3.11.6-amd64.exe
set PYTHON_INSTALLER_URL=https://www.python.org/ftp/python/3.11.6/python-3.11.6-amd64.exe
if not exist "%PYTHON_INSTALLER_PATH%" (
echo %date% %time% - Python installer was not downloaded. Prompting user for options... >> %LOGFILE%
echo The Python 3.11.6 installer was not downloaded successfully.
echo 1. Open the download link in your default browser
echo 2. Attempt to automatically install Python again
echo 3. Exit script
set /p user_choice="Please select an option (1/2/3): "
if /i "%user_choice%"=="1" (
start "" "%PYTHON_INSTALLER_URL%"
) else if /i "%user_choice%"=="2" (
goto DownloadPython
) else (
echo Exiting script...
exit /B
)
echo Please download and install Python manually if the auto-install option failed.
echo Make sure to install it to C:\Python311 and select all the options changing Python directory to C:\Python311 for the script to work.
pause
goto CheckforPython3.11
) else (
echo %date% %time% - Creating a shortcut to the Python installer on the Desktop... >> %LOGFILE%
@powershell -NoProfile -ExecutionPolicy Bypass -Command "$WScriptShell = New-Object -ComObject WScript.Shell; $Shortcut = $WScriptShell.CreateShortcut('$env:USERPROFILE\Desktop\Python 3.11.6 Installer.lnk'); $Shortcut.TargetPath = '%PYTHON_INSTALLER_PATH%'; $Shortcut.Save()"
echo %date% %time% - Shortcut created. >> %LOGFILE%
echo A shortcut to the Python installer has been placed on your desktop.
echo Please run it and select all default options for installation.
pause
)
cls && goto VerifyPython3.11
:VerifyPython3.11
echo Checking for Python in PATH... >> %LOGFILE%
set python_path=C:\Python311\python.exe
if exist "!python_path!" (
echo Found !python_path! >> %LOGFILE%
"!python_path!" --version >> %LOGFILE%
goto Beginactualscriptcommands
) else (
echo Python 3.11.6 not found at expected location. >> %LOGFILE%
exit /B
)
:Beginactualscriptcommands
echo Upgrading pip... >> %LOGFILE%
:: Try to download get-pip.py with aria2 first
echo %date% %time% - Attempting to download get-pip.py using aria2... >> %LOGFILE%
aria2c.exe --disable-ipv6 -x 4 -o "get-pip.py" -d "C:\NexTool" --allow-overwrite=true "https://bootstrap.pypa.io/get-pip.py"
if "%errorlevel%"=="0" (
echo %date% %time% - Downloaded get-pip.py successfully with aria2 >> %LOGFILE%
) else (
echo %date% %time% - Failed to download get-pip.py with aria2. Trying PowerShell... >> %LOGFILE%
powershell.exe pwsh -Command "Invoke-WebRequest -Uri 'https://bootstrap.pypa.io/get-pip.py' -OutFile 'C:\NexTool\get-pip.py'"
if errorlevel 1 (
echo %date% %time% - Failed to download get-pip.py with both methods >> %LOGFILE%
echo Error: Failed to download get-pip.py. Aborting... >> %LOGFILE%
exit /b
) else (
echo %date% %time% - Downloaded get-pip.py successfully with PowerShell >> %LOGFILE%
)
)
:: Upgrade pip using get-pip.py
echo %date% %time% - Upgrading pip... >> %LOGFILE%
"!python_path!" "C:\NexTool\get-pip.py"
if errorlevel 1 (
echo %date% %time% - Error: Failed to upgrade pip >> %LOGFILE%
echo Error: Failed to upgrade pip. Aborting... >> %LOGFILE%
exit /b
) else (
echo %date% %time% - Successfully upgraded pip >> %LOGFILE%
)
echo Installing/upgrading setuptools for Python 3.11... >> %LOGFILE%
"!python_path!" -m pip install --upgrade setuptools
if errorlevel 1 (
echo Error: Failed to install/upgrade setuptools >> %LOGFILE%
) else (
echo Success: setuptools installed/upgraded successfully >> %LOGFILE%
)
echo Installing/upgrading pyqt5-tools for Python 3.11... >> %LOGFILE%
"!python_path!" -m pip install --upgrade pyqt5-tools
if errorlevel 1 (
echo Error: Failed to install/upgrade pyqt5-tools >> %LOGFILE%
) else (
echo Success: pyqt5-tools installed/upgraded successfully >> %LOGFILE%
)
echo Installing/upgrading PyQt5-stubs for Python 3.11... >> %LOGFILE%
"!python_path!" -m pip install --upgrade PyQt5-stubs
if errorlevel 1 (
echo Error: Failed to install/upgrade PyQt5-stubs >> %LOGFILE%
) else (
echo Success: PyQt5-stubs installed/upgraded >> %LOGFILE%
)
echo Installing/upgrading pyqtgraph for Python 3.11... >> %LOGFILE%
"!python_path!" -m pip install --upgrade pyqtgraph
if errorlevel 1 (
echo Error: Failed to install/upgrade pyqtgraph >> %LOGFILE%
) else (
echo Success: pyqtgraph installed/upgraded successfully >> %LOGFILE%
)
echo Installing/upgrading requests for Python 3.11... >> %LOGFILE%
"!python_path!" -m pip install --upgrade requests
if errorlevel 1 (
echo Error: Failed to install/upgrade requests >> %LOGFILE%
) else (
echo Success: requests installed/upgraded successfully >> %LOGFILE%
)
echo Installing/upgrading psutil for Python 3.11... >> %LOGFILE%
"!python_path!" -m pip install --upgrade psutil
if errorlevel 1 (
echo Error: Failed to install/upgrade psutil >> %LOGFILE%
) else (
echo Success: psutil installed/upgraded successfully >> %LOGFILE%
)
echo Installing/upgrading pywin32 for Python 3.11... >> %LOGFILE%
"!python_path!" -m pip install --upgrade pywin32
if errorlevel 1 (
echo Error: Failed to install/upgrade pywin32 >> %LOGFILE%
) else (
echo Success: pywin32 installed/upgraded successfully >> %LOGFILE%
)
cls
:DownloadNexTool
setlocal
echo %date% %time% - Attempting download using aria2... >> %LOGFILE%
aria2c --disable-ipv6 -x 4 -o "NexTool.py" -d "C:\NexTool" --allow-overwrite=true "https://raw.githubusercontent.com/coff33ninja/NexTool-Windows-Suite/main/NexTool.py"
if "%errorlevel%"=="0" (
echo %date% %time% - Downloaded successfully with aria2 >> %LOGFILE%
endlocal && set "DOWNLOAD_RESULT=0"
goto LaunchNexTool
) else (
echo %date% %time% - Failed to download with aria2. Trying PowerShell... >> %LOGFILE%
pwsh -Command "Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/coff33ninja/NexTool-Windows-Suite/main/NexTool.py' -OutFile 'C:\NexTool\NexTool.py'"
if "%errorlevel%"=="0" (
echo %date% %time% - Downloaded successfully with PowerShell >> %LOGFILE%
endlocal && set "DOWNLOAD_RESULT=0"
) else (
echo %date% %time% - Download failed with both methods >> %LOGFILE%
endlocal && set "DOWNLOAD_RESULT=1"
)
goto LaunchNexTool
)
:LaunchNexTool
:: Run the chosen Python version for your script
if exist "C:/NexTool/NexTool.py" (
echo Launching NexTool.py
start /wait "" "!python_path!" "C:/NexTool/NexTool.py"
) else (
echo Failed to download NexTool.py
)
echo. >> %LOGFILE%
echo Installation Summary: >> %LOGFILE%
echo --------------------- >> %LOGFILE%
type %LOGFILE% | find "Failed" >nul
if errorlevel 1 (
echo All installations were successful! >> %LOGFILE%
echo All installations were successful!
) else (
echo Some installations failed. Check the log for details. >> %LOGFILE%
echo Some installations failed. Check the log for details.
)
pause
set /p user_input="Do you want to review the log? (yes/no): "
if /i "%user_input%"=="yes" (
start /wait notepad %LOGFILE%
)
echo Deleting contents of C:\Nex Tool...
for /R "C:\NexTool" %%i in (*) do (
del "%%i"
)
for /D %%i in (C:\NexTool\*) do (
rmdir /s /q "%%i"
)
echo Removing C:\NexTool directory...
rmdir "C:\NexTool"
echo Cleanup complete. Exiting script...
endlocal
exit /B