纯批的请测试...
-
- @echo off
- Title 欢迎使用批处理之家(备份驱动脚本) BY: fastslz
- :::网上论坛: http://bbs.bathome.net/
- :::个性空间: http://groups.google.com/group/fastslz
- Set Tools=%~dps0Tools
- if not %OS%==Windows_NT (color 0c&%Tools%\sleep.exe -k -p "此程序必须在Windows NT或XP以上操作系统上运行" 10&exit)
- %Tools%\devcon.exe>nul 2>nul
- if %errorlevel%==9009 (color 0c&%Tools%\sleep.exe -k -p "本脚本需要微软 %Tools%\devcon.exe 命令行实用工具支持" 10&exit)
- set Tempfile="%Temp:"=%.\fast.slz"
- set "BakPath=%~dp0Drivers"
- del %Tempfile% 2>nul
- cls&color 0b&set count=0
- echo 正在收集设备信息,请稍等...
- for /f "skip=1 tokens=2,3,4 delims=," %%a in ('Wmic Path Win32_PnPSignedDriver where "infname like 'oem%%'" get infname^,DeviceName^,HardWareID /format:csv') do >>%Tempfile% echo."%%a","%%b","%%c"|more>nul
- dir /ad "%BakPath%" >nul 2>nul||MD "%BakPath%"
- for /f "tokens=1,2,3 delims=," %%i in ('type %Tempfile%^|find /i "oem"') do call :DevStart %%i %%j %%k
- del %Tempfile% 2>nul
- echo.
- %Tools%\sleep.exe -p "备份已完成!一共备份了 %count% 项设备驱动" 3
- echo.&color 0a
- %Tools%\sleep.exe -k -p "按下任意键开始打包集成驱动,15秒内未做选择默认自动退出" 15
- if %errorlevel%==0 exit/b0
- for /f "delims=*" %%a in ('dir /s/a-d/b Driver.nfo 2^>nul') do call :Pack "%%a"
- cls&echo.&color 0b
- %Tools%\sleep.exe -k -p "打包已完成!10 秒后自动退出" 10
- exit
- :DevStart
- if "%~1"=="" goto:eof
- color 0e
- if %count% equ 0 cls
- setlocal enabledelayedexpansion
- Set "DeviceName=%~1"
- Set "DevName=!DeviceName:/= !"
- Set "DevName=!DevName:\= !"
- Set "DevName=!DevName:?= !"
- Set "DevName=!DevName:|= !"
- Set "DevName=!DevName:>= !"
- Set "DevName=!DevName:<= !"
- Set "DevName=!DevName:^*= !"
- set "HardWareID=%~2"
- set "HardWareID=!HardWareID:&=&!"
- dir /ad "%BakPath%\%DevName%" >nul 2>nul||MD "%BakPath%\%DevName%"
- >"%BakPath%\%DevName%\Driver.nfo" set /p=DeviceName=%DeviceName%<nul
- >>"%BakPath%\%DevName%\Driver.nfo" echo.
- >>"%BakPath%\%DevName%\Driver.nfo" set /p="HardWareID=%HardWareID%"<nul
- >>"%BakPath%\%DevName%\Driver.nfo" echo.
- >>"%BakPath%\%DevName%\Driver.nfo" set /p="InfName=%~3"<nul
- set/p=正在备份--^> "%~1"<nul
- For /F "skip=1 tokens=*" %%i in ('%Tools%\devcon.exe Driverfiles "%HardWareID%"^|find ":\"') do xcopy /h/r/y %%~si "%BakPath%\%DevName%" >nul 2>nul
- xcopy /h/r/y "%Systemroot%\Inf\%~3" "%BakPath%\%DevName%" >nul 2>nul
- if errorlevel 0 set /a "count=%count%+1"
- set "InfName=%~n3"
- for /f "tokens=1* delims== " %%k in ('type "%Systemroot%\Inf\%InfName%.inf"^|find /i ".Cat"^|find /v "64"') do set "OemName=%%~nl"
- if defined OemName (
- for /f "delims=*" %%a in ('dir /s/b/a-d "%SystemRoot%\system32\CatRoot\%InfName%.cat" 2^>nul') do set "catfile=%%~a"
- if not defined catfile for /f "delims=*" %%k in ('dir /s/b/a-d "%SystemRoot%\%OemName%.cat" 2^>nul') do set "catfile=%%~k"
- )
- if defined catfile (
- set "InfName=%OemName%"
- xcopy /h/r/y "%catfile%" "%BakPath%\%DevName%\">nul 2>nul
- if errorlevel 0 echo 含WHQL数字签名
- attrib -s -h -r "%BakPath%\%DevName%\%InfName%.*">nul
- copy /y "%BakPath%\%DevName%\Driver.nfo" "%BakPath%\%DevName%\Driver.bak">nul 2>nul
- type "%BakPath%\%DevName%\Driver.bak"|find /v "InfName=">"%BakPath%\%DevName%\Driver.nfo"
- >>"%BakPath%\%DevName%\Driver.nfo" echo InfName=%OemName%.inf&del "%BakPath%\%DevName%\Driver.bak" 2>nul
- move /y "%BakPath%\%DevName%\%InfName%.inf" "%BakPath%\%DevName%\%OemName%.inf">nul 2>nul
- move /y "%BakPath%\%DevName%\%InfName%.cat" "%BakPath%\%DevName%\%OemName%.cat">nul 2>nul
- )
- endlocal&set count=%count%
- goto:eof
- :Pack
- if "%~1"=="" goto:eof
- set "DriverPath=%~dp1"
- set "Name=%DriverPath:~0,-1%"
- for /f "delims=*" %%a in ("%Name%.tmp") do set "Name=%%~na"
- cls&echo 正在集成 %Name% 驱动包请稍等...
- %Tools%\7za.exe a -sfxdev.sfx "%Name%.exe" "%DriverPath%*.*" "%Tools%\devcon.exe" "%Tools%\sleep.exe" "%Tools%\Update.cmd"
- rem rd /s/q "%DriverPath%"
- goto:eof
复制代码
[ 本帖最后由 fastslz 于 2009-4-12 20:09 编辑 ] |