本帖最后由 yakeyun 于 2023-1-9 18:41 编辑
回复 17# idwma
type这个代码更精准,之前打不上的已经可以打上了。应该是这个代码匹配了带*字符前缀的硬件ID。
测试视频:https://sanli.lanzoub.com/iiaIR0kk1uqd
测试包裹:https://sanli.lanzoub.com/iUi0u0kk54ej
修改后有2个版本:
一个是先把匹配的驱动文件输出到install.txt,然后再读取安装。
一个是一边匹配一边安装,感觉第二种速度更快,节省了安装等待时间。
成品代码如下:- @echo off
- cd /d "%~dp0"
- mode con cols=50 lines=20
- setlocal enabledelayedexpansion
-
- ::禁用指定ID的RAID硬件,并刷新硬件列表。
- call "%SystemRoot%\system32\pnputil.exe" /disable-device "PCI\VEN_8086&DEV_A77F&SUBSYS_88821043&REV_00\3&11583659&0&70"
- call "%SystemRoot%\system32\pnputil.exe" /disable-device "PCI\VEN_8086&DEV_A77F&SUBSYS_86941043&REV_00\3&11583659&0&70"
- call "%SystemRoot%\system32\pnputil.exe" /disable-device "PCI\VEN_8086&DEV_467F&SUBSYS_86941043&REV_00\3&11583659&0&70"
- call "%SystemRoot%\system32\pnputil.exe" /disable-device "PCI\VEN_8086&DEV_467F&SUBSYS_00008086&REV_00\3&11583659&0&70"
- call "%SystemRoot%\system32\pnputil.exe" /disable-device "PCI\VEN_8086&DEV_A77F&SUBSYS_86941043&REV_00\3&11583659&0&70"
- call "%SystemRoot%\system32\pnputil.exe" /scan-devices
- cls
- ::=========================提取驱动文件=========================
- for /f %%e in ('wmic cpu get name^ /value ^|find /i "intel"') do ((for /f "tokens=* delims=, " %%b in ('dir /a /s /b .\intels\*.inf ') do echo %%b)>"inf.txt")
- for /f %%a in ('wmic cpu get name^ /value ^|find /i "AMD"') do ((for /f "tokens=* delims=, " %%b in ('dir /a /s /b .\amds\*.inf ') do echo %%b)>"inf.txt")
- (for /f "tokens=* delims=, " %%b in ('dir /a /s /b .\Public\*.inf ') do echo %%b)>>"inf.txt"
- ::========================提取驱动ID信息=========================
- :run
- pnputil /enum-devices /problem 28 /ids >.\ID.txt
- for /f %%s in ('type "ID.TXT" ^|find "在系统上找不到任何设备"') do (goto END)
- ::======================通过ID匹配驱动安装驱动======================
- (
- (for /f "tokens=1,3 delims= " %%a in ('findstr "\\" "ID.txt"') do (
- if "%%b"=="" (
- set /p "=for /f "delims=" %%%%i in (inf.txt) do ("<nul
- echo;
- set /p "=type "%%%%i"|findstr /c:"%%a">nul&&echo "%%%%i" >>install.txt&&goto :id!nn!"<nul
- echo;
- set /p "=)"<nul
- echo;
- ) else if "%%a"=="实例" (
- set /a n+=1
- set /a nn=!n!+1
- echo :id!n!
- ) else (
- set /p "=for /f "delims=" %%%%i in (inf.txt) do ("<nul
- echo;
- set /p "=type "%%%%i"|findstr /c:"%%b">nul&&echo "%%%%i" >>install.txt&&goto :id!nn!"<nul
- echo;
- set /p "=)"<nul
- echo;
- )
- ))
- set /a n+=1
- echo :id!n!
- )>ids.bat
- call ids.bat
-
- (for /f %%i in (install.txt) do (
- start /min "" "%SystemRoot%\system32\pnputil.exe" /add-driver %%i /install
- ))
- if exist install.txt del install.txt
- ::刷新硬件列表更新硬件状态
- call "%SystemRoot%\system32\pnputil.exe" /scan-devices
-
- cls
- ECHO,1> NO1.DLL
- ::======================再次检测是否有硬件没有打上驱动======================
- if exist NO1.DLL (del NO1.DLL && call :run)
- ::=============================清理战场=============================
- :END
- IF EXIST INSTALL.TXT DEL INSTALL.TXT
- IF EXIST ID.TXT DEL ID.TXT
- IF EXIST INF.TXT DEL INF.TXT
- IF EXIST IDS.BAT DEL IDS.BAT
- IF EXIST NO1.DLL DEL NO1.DLL
-
- exit
复制代码 修改后的版本,边匹配边安装,感觉速度更快:- @echo off
- cd /d "%~dp0"
- mode con cols=50 lines=20
- setlocal enabledelayedexpansion
-
- ::禁用指定ID的RAID硬件,并刷新硬件列表。
- call "%SystemRoot%\system32\pnputil.exe" /disable-device "PCI\VEN_8086&DEV_A77F&SUBSYS_88821043&REV_00\3&11583659&0&70"
- call "%SystemRoot%\system32\pnputil.exe" /disable-device "PCI\VEN_8086&DEV_A77F&SUBSYS_86941043&REV_00\3&11583659&0&70"
- call "%SystemRoot%\system32\pnputil.exe" /disable-device "PCI\VEN_8086&DEV_467F&SUBSYS_86941043&REV_00\3&11583659&0&70"
- call "%SystemRoot%\system32\pnputil.exe" /disable-device "PCI\VEN_8086&DEV_467F&SUBSYS_00008086&REV_00\3&11583659&0&70"
- call "%SystemRoot%\system32\pnputil.exe" /disable-device "PCI\VEN_8086&DEV_A77F&SUBSYS_86941043&REV_00\3&11583659&0&70"
- call "%SystemRoot%\system32\pnputil.exe" /scan-devices
- cls
- ::=========================提取驱动文件=========================
- for /f %%e in ('wmic cpu get name^ /value ^|find /i "intel"') do ((for /f "tokens=* delims=, " %%b in ('dir /a /s /b .\intels\*.inf ') do echo %%b)>"inf.txt")
- for /f %%a in ('wmic cpu get name^ /value ^|find /i "AMD"') do ((for /f "tokens=* delims=, " %%b in ('dir /a /s /b .\amds\*.inf ') do echo %%b)>"inf.txt")
- (for /f "tokens=* delims=, " %%b in ('dir /a /s /b .\Public\*.inf ') do echo %%b)>>"inf.txt"
- ::========================提取驱动ID信息=========================
- :run
- pnputil /enum-devices /problem 28 /ids >.\ID.txt
- for /f %%s in ('type "ID.TXT" ^|find "在系统上找不到任何设备"') do (goto END)
- ::======================通过ID匹配驱动安装驱动======================
- (
- (for /f "tokens=1,3 delims= " %%a in ('findstr "\\" "ID.txt"') do (
- if "%%b"=="" (
- set /p "=for /f "delims=" %%%%i in (inf.txt) do ("<nul
- echo;
- set /p "=type "%%%%i"|findstr /c:"%%a">nul&&start /min "" "%SystemRoot%\system32\pnputil.exe" /add-driver "%%%%i" /install&&goto :id!nn!"<nul
- echo;
- set /p "=)"<nul
- echo;
- ) else if "%%a"=="实例" (
- set /a n+=1
- set /a nn=!n!+1
- echo :id!n!
- ) else (
- set /p "=for /f "delims=" %%%%i in (inf.txt) do ("<nul
- echo;
- set /p "=type "%%%%i"|findstr /c:"%%b">nul&&start /min "" "%SystemRoot%\system32\pnputil.exe" /add-driver "%%%%i" /install&&goto :id!nn!"<nul
- echo;
- set /p "=)"<nul
- echo;
- )
- ))
- set /a n+=1
- echo :id!n!
- )>ids.bat
- call ids.bat
-
- ::刷新硬件列表更新硬件状态
- call "%SystemRoot%\system32\pnputil.exe" /scan-devices
- cls
- ECHO,1> NO1.DLL
- ::======================再次检测是否有硬件没有打上驱动======================
- if exist NO1.DLL (del NO1.DLL && call :run)
- ::=============================清理战场=============================
- :END
- IF EXIST INSTALL.TXT DEL INSTALL.TXT
- IF EXIST ID.TXT DEL ID.TXT
- IF EXIST INF.TXT DEL INF.TXT
- IF EXIST IDS.BAT DEL IDS.BAT
- IF EXIST NO1.DLL DEL NO1.DLL
-
- exit
复制代码
|