|
| 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