|
::petools扩展目录搜索安装程序 by chenall [url=http://bbs.wuyou.net/forum.php?mod=viewthread&tid=158014[/color[/url]]
::思路来源:[url=http://bbs.wuyou.net/forum.php?mod=viewthread&tid=140951http://bbs.wuyou.net/forum.php?mod=viewthread&tid=140951[/color[/url]]
::调用方式
::PETOOLS_LNK [PETOOLS目录]
::PECMD调用例子,查找所有petools目录。
::PECMD FORX @\PETOOLS,TOOLS,0,!EXEC CMD /C “PETOOLS_LINK %TOOLS%”
::2009-12-22 第三版,2009-12-23,修改了执行SETUP.BAT/CMD的调用方式为START /W,解决碰到EXIT退出的问题.
::2009-12-23,对于注册表文件只自动注册setup_reg.reg,其它的可以由setup.cmd来调用.以免重复执行
@echo off
if "%~1"=="" goto :eof
if not defined StartMenu SET "StartMenu=%USERPROFILE%\「开始」菜单"
if "%~1"=="merge" goto :merge
if not exist "%~1" goto :eof
SET "BASE_DIR=%~1"
SET "外置程序=PETOOLS_%~d1盘"
SET "外置程序=%StartMenu%\%外置程序::=%"
SET "_TF=%WinDir%\T_PETOOLS_%base_dir:~0,1%_"
IF EXIST "%外置程序%" RD /S /Q "%外置程序%" 2>nul
:START
DEL "%_TF%*.*" 2>nul
PUSHD "%~F1"
>%_TF%LST.lst dir /s/a/b *.wim *.bat *.exe *.wcs *.cmd *.txt *.msu *.iso
POPD
PUSHD "%WinDir%"
for /f "usebackq delims=" %%i in (%_TF%LST.lst) do CALL :MAKE_LINK "%%i"
ECHO.EXEC !%~F0 merge "%外置程序%" >>%_TF%LNK.INI
ECHO.FILE %_TF%LNK.INI>>%_TF%LNK.INI
START PECMD LOAD %_TF%LNK.INI
PUSHD "%~F1"
>"%_TF%REG.lst" dir /s/a/b SETUP_REG.REG 2>nul
>"%_TF%INF.lst" dir /s/a/b setup.inf 2>nul
POPD
if exist "%_TF%REG.LST" for /f "usebackq delims=" %%i in ("%_TF%REG.LST") do REGEDIT /S "%%i"
if exist "%_TF%INF.lst" for /f "usebackq delims=" %%i in ("%_TF%INF.lst") do RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection DefaultInstall 128 %%i
IF EXIST "%_TF%SETUP.LST" for /f "usebackq delims=" %%i in ("%_TF%SETUP.LST") do CALL :PETOOLS_SETUP "%%i"
DEL %_TF%*.lst
POPD
goto :eof
:MAKE_LINK
::如果有包含AutoRuns就跳过.
echo.%1|find /i "\AutoRuns\" &&goto :eof
echo.%1|find /i "\三卡驱动\" &&goto :eof
SETLOCAL
if "%~1"=="" goto :eof
if /i "%~n1"=="setup" (
echo.%1 >>"%_TF%SETUP.LST"
goto :eof
)
SET ".=%~1"
SET ".=%.:&=^&%"
SET "PETOOLS=%~dpn1"
call,SET "PETOOLS=%%PETOOLS:%BASE_DIR%=%外置程序%%%"
SET "PETOOLS=%PETOOLS:&=^&%"
echo.LINK %PETOOLS%,%.%>>%_TF%LNK.INI
GOTO :EOF
:PETOOLS_SETUP
::为什么需要这些步骤呢,因为考虑到有一些批处理对执行目录的要求(编写时没有考虑到),所以才需要进入批处理目录执行.否则可能会出错.表面上是执行了,其实执行的结果是错误的.用PECMD调用同样会有这样的问题.
pushd "%~dp1"
PECMD EXEC !%~nx1
POPD
goto :eof
:merge
PUSHD %2||GOTO :EOF
for /d %%i in ("%~2\*") do call :merge_lnk "%%i"
POPD
goto :eof
:merge_lnk
CD /D %1||GOTO :EOF
for /d %%i in ("%~f1\*") do call %0 "%%i"
CD /D %1||GOTO :EOF
set n=
for /f %%i in ('dir /a/b') do (
if defined n goto :eof
set n=1
)
for /f "usebackq delims=" %%i in (`dir /a/b`) do move /y "%%i" ..\
cd..&&rd %1
goto :eof
在本坛找了个批处理,直接运行生成菜单, 简单快捷不用自己码字。
|
|