(图片来源网络,侵删)
在重新安装Windows操作系统时,原来安装的驱动程序如果可以备份下来,装完系统后就可以非常方便的通过设备管理器把未被识别的设备驱动安装上。如果通过第三方软件,很容易被安装垃圾软件,可以通过脚本实现。此脚本支持32位和64位Windows,脚本所在目录下的x86(32位)和x64(64位)目录存放备份出来的驱动程序。脚本如下:@echo offcls:: 获得管理员权限的批命令:--------------------------------------------------------------------------------REM --> 检查权限>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"REM --> 如果设置了错误标志,表明没有管理员权限。if '%errorlevel%' NEQ '0' (echo 正在请求管理员权限...goto UACPrompt) else ( goto gotAdmin ):UACPromptecho Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs""%temp%\getadmin.vbs"exit /B:gotAdminif exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )pushd "%CD%"CD /D "%~dp0":-----------------------------------------------------------------------------if "%PROCESSOR_ARCHITECTURE%" == "x86" (set OS_TP=x86) else (set OS_TP=x64)echo 正在备份第三方驱动程序,请稍候...echo.setlocal enabledelayedexpansionset WINDRV=%windir%\System32\DriverStore\FileRepositoryDism /Online /Get-Drivers /Format:Table|findstr /I ".inf">tmp0.txt@echo off>tmp1.txtfor /f "tokens=4,2 delims=^| " %%i in (tmp0.txt) do (echo %%j,%%i>>tmp1.txt)sort tmp1.txt>tmp2.txtif exist %~dp0%OS_TP% rmdir /S /Q %~dp0%OS_TP%for /f "delims=," %%i in (tmp2.txt) do (if not defined %%i set %%i=A & mkdir %~dp0%OS_TP%\%%i)for /f "tokens=2,1 delims=," %%i in (tmp2.txt) do (set SOURCE_DRV=%%jfor /f "delims=" %%l in ('dir /b "!WINDRV!\!SOURCE_DRV!"') do (set COPYDIR=%WINDRV%\%SOURCE_DRV%\%%l::显示进度条set /p=^><nulxcopy /herky /Q !COPYDIR! %~dp0%OS_TP%\%%i\%%l\>nul))if exist tmp0.txt del /Q tmp0.txtif exist tmp1.txt del /Q tmp1.txtif exist tmp2.txt del /Q tmp2.txttimeout -t 5exit
0 评论