Skip to content

Commit 2cabf29

Browse files
committed
Initial commit.
0 parents  commit 2cabf29

File tree

5 files changed

+264
-0
lines changed

5 files changed

+264
-0
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.bat text eol=crlf

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.exe

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018, XhmikosR.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# slim-nvidia-drivers
2+
3+
This is a Windows script which simply removes the unneeded stuff/bloatware from NVIDIA drivers
4+
package and creates a new archive.
5+
6+
**WARNING**: USE AT YOUR OWN RISK!
7+
8+
## Drivers tested:
9+
10+
v388 - v391
11+
12+
## Requirements:
13+
14+
* a) [7-Zip](https://www.7-zip.org/download.html) installed or b) [7za.exe](https://www.7-zip.org/download.html) in your `%PATH%`, or in the same folder as this script
15+
* A recent Windows version; the script is only tested on Windows 10
16+
* The NVIDIA driver already downloaded somewhere on your computer :)
17+
18+
## Usage:
19+
20+
```
21+
slim-nvidia-drivers.bat NVIDIA_DRIVER_FILE.exe
22+
```
23+
24+
This will create two 7z archives, minimal and slim:
25+
26+
* "minimal" includes only the driver
27+
* "slim" includes the driver, HDAudio and PhysX
28+
29+
## License
30+
31+
MIT

slim-nvidia-drivers.bat

+210
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
@echo off
2+
3+
rem --------------------------------------------------
4+
rem A Windows batch file to slim down NVIDIA drivers.
5+
rem Author: XhmikosR
6+
rem Licensed under the MIT License
7+
rem See help for more info
8+
rem --------------------------------------------------
9+
10+
11+
:start
12+
setlocal
13+
14+
set "FOLDERS_TO_KEEP_MINIMAL=Display.Driver NVI2"
15+
set "FOLDERS_TO_KEEP_SLIM=Display.Driver HDAudio NVI2 PhysX"
16+
set "FILES_TO_KEEP_MINIMAL=EULA.txt license.txt ListDevices.txt setup.cfg setup.exe"
17+
set "FILES_TO_KEEP_SLIM=%FILES_TO_KEEP_MINIMAL%"
18+
19+
set "BATCH_FILENAME=%~nx0"
20+
set "ARG1=%~1"
21+
set "FULL_PATH=%ARG1%"
22+
set "FILENAME=%~n1"
23+
set "WORK_FOLDER=%FILENAME%"
24+
set "SCRIPT_VERSION=0.1"
25+
26+
title %BATCH_FILENAME% %FILENAME%
27+
28+
rem Check if any argument is passed; if not show the help screen
29+
if "%ARG1%" == "" goto help
30+
if "%ARG1%" == "--help" goto help
31+
if "%ARG1%" == "-help" goto help
32+
if "%ARG1%" == "/help" goto help
33+
34+
rem Try to detect 7-Zip or 7za.exe; if none is found, show a message and exit
35+
call :detectSevenzipPath
36+
37+
if not exist "%SEVENZIP%" (
38+
echo 7-Zip or 7za.exe wasn't found!
39+
echo You can install 7-Zip, or place 7za.exe in your %%PATH%%, or in the same folder as this script.
40+
goto exit
41+
)
42+
43+
rem Switch to the batch file's directory
44+
cd /d %~dp0
45+
46+
rem If the file doesn't exist show a message and exit
47+
if not exist "%FULL_PATH%" (
48+
echo "%FULL_PATH%" wasn't found! & goto exit
49+
)
50+
51+
rem Remove the old folder if it exists
52+
if exist "%WORK_FOLDER%" rd /q /s "%WORK_FOLDER%"
53+
54+
rem Extract the driver
55+
"%SEVENZIP%" x "%FULL_PATH%" -o"%WORK_FOLDER%"
56+
if %ERRORLEVEL% neq 0 (
57+
echo. & echo *** [ERROR] Extracting "%FULL_PATH%" failed! & echo.
58+
goto exit
59+
)
60+
61+
rem Switch to the drivers folder
62+
pushd "%WORK_FOLDER%"
63+
64+
rem Minimal
65+
call :copy "minimal"
66+
if ERRORLEVEL 1 goto exit
67+
call :create_archive "minimal"
68+
if ERRORLEVEL 1 goto exit
69+
70+
rem Slim
71+
call :copy "slim"
72+
if ERRORLEVEL 1 goto exit
73+
call :create_archive "slim"
74+
if ERRORLEVEL 1 goto exit
75+
76+
popd
77+
78+
rem Remove the drivers folder
79+
rd /q /s "%WORK_FOLDER%"
80+
81+
82+
:exit
83+
endlocal
84+
echo. & echo Press any key to close this window...
85+
pause >nul
86+
exit /b
87+
88+
89+
rem Subroutines
90+
:help
91+
echo --------------------------------------------------
92+
echo %BATCH_FILENAME% v%SCRIPT_VERSION%
93+
echo A Windows batch file to slim down NVIDIA drivers.
94+
echo Author: XhmikosR
95+
echo Licensed under the MIT License
96+
echo.
97+
echo Requirements:
98+
echo * a) 7-Zip installed or b) 7za.exe in your %%PATH%%, or in the same folder as this script
99+
echo * A recent Windows version; the script is only tested on Windows 10
100+
echo * The NVIDIA driver already downloaded somewhere on your computer :)
101+
echo.
102+
echo Usage: %BATCH_FILENAME% NVIDIA_DRIVER_FILE.exe
103+
echo.
104+
echo This will create two 7z archives, minimal and slim:
105+
echo * "minimal" includes only the driver
106+
echo * "slim" includes the driver, HDAudio and PhysX
107+
echo --------------------------------------------------
108+
goto exit
109+
110+
111+
:copy
112+
set "TYPE=%~1"
113+
set "TEMP_DIR=_temp_%TYPE%"
114+
115+
rem Create a temporary folder
116+
if not exist "%TEMP_DIR%" mkdir "%TEMP_DIR%"
117+
118+
rem Copy all the things
119+
call :copy_folders "%TYPE%"
120+
if ERRORLEVEL 1 exit /b %ERRORLEVEL%
121+
call :copy_files "%TYPE%"
122+
if ERRORLEVEL 1 exit /b %ERRORLEVEL%
123+
124+
exit /b 0
125+
126+
127+
:copy_folders
128+
if "%TYPE%" == "minimal" (
129+
set "TEMP_FOLDERS_TO_KEEP=%FOLDERS_TO_KEEP_MINIMAL%"
130+
) else (
131+
set "TEMP_FOLDERS_TO_KEEP=%FOLDERS_TO_KEEP_SLIM%"
132+
)
133+
134+
rem Copy the folders we want to keep into the temporary folder
135+
for /d %%G in (%TEMP_FOLDERS_TO_KEEP%) do (
136+
if not exist "%%G" (
137+
echo. & echo *** [ERROR] "%%G" doesn't exist in the drivers file! & echo.
138+
exit /b 1
139+
)
140+
141+
xcopy "%%G" "%TEMP_DIR%\%%G" /i /s /h /e /k /q /r /y /v
142+
if %ERRORLEVEL% neq 0 (
143+
echo. & echo *** [ERROR] Copying folders failed! & echo.
144+
exit /b 1
145+
)
146+
)
147+
148+
exit /b 0
149+
150+
151+
:copy_files
152+
if "%TYPE%" == "minimal" (
153+
set "TEMP_FILES_TO_KEEP=%FILES_TO_KEEP_MINIMAL%"
154+
) else (
155+
set "TEMP_FILES_TO_KEEP=%FILES_TO_KEEP_SLIM%"
156+
)
157+
158+
rem Copy the files we want to keep into the temporary folder
159+
for %%G in (%TEMP_FILES_TO_KEEP%) do (
160+
if not exist "%%G" (
161+
echo. & echo *** [ERROR] "%%G" doesn't exist in the drivers file! & echo.
162+
exit /b 1
163+
)
164+
165+
copy /y /v "%%G" "%TEMP_DIR%\"
166+
if %ERRORLEVEL% neq 0 (
167+
echo. & echo *** [ERROR] Copying files failed! & echo.
168+
exit /b 1
169+
)
170+
)
171+
172+
exit /b 0
173+
174+
175+
:create_archive
176+
rem Rename the temporary directory
177+
set "TEMP_ARCHIVE_DIR=%FILENAME%_%TYPE%"
178+
rename "%TEMP_DIR%" "%TEMP_ARCHIVE_DIR%"
179+
180+
rem Just in case NUMBER_OF_PROCESSORS isn't defined
181+
if not defined NUMBER_OF_PROCESSORS set NUMBER_OF_PROCESSORS=4
182+
183+
rem Create the new archive
184+
start "7-Zip" /b /wait "%SEVENZIP%" a -t7z ""%TEMP_ARCHIVE_DIR%.7z"" ""%TEMP_ARCHIVE_DIR%\*"" -mmt=%NUMBER_OF_PROCESSORS% -m0=LZMA2 -mx9
185+
186+
if %ERRORLEVEL% neq 0 (
187+
echo. & echo *** [ERROR] Creating 7z archive! & echo.
188+
exit /b 1
189+
)
190+
191+
move /y "%TEMP_ARCHIVE_DIR%.7z" ".."
192+
193+
rem Remove the temporary folders
194+
if exist "%TEMP_DIR%" rd /q /s "%TEMP_DIR%"
195+
if exist "%TEMP_ARCHIVE_DIR%" rd /q /s "%TEMP_ARCHIVE_DIR%"
196+
197+
exit /b 0
198+
199+
200+
:detectSevenzipPath
201+
for %%G in (7z.exe) do (set "SEVENZIP_PATH=%%~$PATH:G")
202+
if exist "%SEVENZIP_PATH%" (set "SEVENZIP=%SEVENZIP_PATH%" & exit /b)
203+
204+
for %%G in (7za.exe) do (set "SEVENZIP_PATH=%%~$PATH:G")
205+
if exist "%SEVENZIP_PATH%" (set "SEVENZIP=%SEVENZIP_PATH%" & exit /b)
206+
207+
for /f "tokens=2*" %%A in (
208+
'reg QUERY "HKLM\SOFTWARE\7-Zip" /v "Path" 2^>nul ^| find "REG_SZ" ^|^|
209+
reg QUERY "HKLM\SOFTWARE\Wow6432Node\7-Zip" /v "Path" 2^>nul ^| find "REG_SZ"') do set "SEVENZIP=%%B\7z.exe"
210+
exit /b 0

0 commit comments

Comments
 (0)