|
用的是批处理配合PECMD的LINK功能。
大家可以试一下:
规则
1.有找到REG文件就先执行注册该文件。
2.有找到PECMD.INI就不进行创建快捷方式,而是直接调用PECMD.INI(用于自定义),并且不再找下一级目录。(新版不支持这个)
3.有找到SETUP.BAT,setup.inf,setup.cmd,自动执行安装
4.搜到*.exe,*.wim,*.bat,*.cmd,并且不是SETUP.*的就创建快捷方式。
5.单个快捷方式合并(比如\其它工具\WINHEX\目录下只有一个WINHEX程序,则会把快捷方式创建在<其它工具>目录下).
Batchfile语言: [A href="http://fayaa.com/code/view/8492/]petools扩展目录搜索安装程序[/A]
::petools扩展目录搜索安装程序 by chenall http://www.chenall.com
::思路来源:http://bbs.wuyou.net/forum.php?mod=viewthread&tid=140951
::调用方式
::PETOOLS_LNK [PETOOLS目录]
::PECMD调用例子,查找所有petools目录。
::PECMD FORX @\PETOOLS,TOOLS,0,!EXEC PETOOLS_LINK %TOOLS%
::
@echo off
PATH %PATH%;%CD%
if not exist "%~F1" goto :eof
SET BASE_DIR=%~pnx1
::SET 外置程序="%StartMenu%\外置程序"
SET "外置程序=外置程序_%~d1盘"
SET "外置程序=%StartMenu%\%外置程序::=%"
IF EXIST "%外置程序%" RD /S /Q "%外置程序%"
MD "%外置程序%"
:START
PUSHD "%~F1"
for /f "delims=" %%a in ('dir /b/ad') do call :MAKE_LINK "%%a"
POPD
goto :eof
:MAKE_LINK
SETLOCAL
CD "%~1"
SET "PETOOLS=%~p1"
SET PETOOLS=%PETOOLS:~0,-1%
CALL,SET "PETOOLS=%%PETOOLS:%BASE_DIR%\=%%"
echo.%PETOOLS%
for %%i in (*.reg) do regedit /s "%%i"
if exist pecmd.ini (
pecmd load pecmd.ini
goto :eof
)
if exist setup.cmd call setup.cmd
if exist setup.bat call setup.bat
if exist setup.inf RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection DefaultInstall 128 "%%~fi"
for %%i in (*.exe,*.wim,*.bat,*.cmd) do (
if /i not "%%~ni"=="setup" PECMD LINK %外置程序%\%PETOOLS%\%%~ni,%%~fi
)
PUSHD "%外置程序%\%PETOOLS%\" 2>nul || GOTO :MAKE_LINK_D
set/an=0
for %%i in (*.lnk) do (
set/an+=1
)
if %n% LEQ 1 (
move /y *.lnk ..\
cd ..
rd /s /q "%外置程序%\%PETOOLS%\"
)
POPD
:MAKE_LINK_D
for /f "delims=" %%a in ('dir /b/ad') do call :MAKE_LINK "%%a"
goto :eof
第二版来了,看起来代码是更多了,但应该效率会有所提升,暂时还没有处理快捷方式合并
- @echo off
- if "%~1"=="" goto :eof
- if not defined StartMenu goto :eof
- if not exist "%~1" goto :eof
- SET "BASE_DIR=%~1"
- SET "外置程序=外置程序_%~d1盘"
- SET "外置程序=%StartMenu%\%外置程序::=%"
- IF EXIST "%外置程序%" RD /S /Q "%外置程序%"
- :START
- del "%temp%\PETOOLS_*.lst" 2>nul
- PUSHD "%~F1"
- >"%temp%\PETOOLS_LST.lst" dir /s/a/b *.wim *.cmd *.bat *.exe readme*.txt 使用说明*.txt
- POPD
- PUSHD "%TEMP%"
- for /f "usebackq delims=" %%i in (PETOOLS_LST.lst) do CALL :MAKE_LINK "%%i"
- START PECMD LOAD PETOOLS_LNK.INI
- PUSHD "%~F1"
- >"%temp%\PETOOLS_REG.lst" dir /s/a/b *.REG 2>nul
- >"%temp%\PETOOLS_INF.lst" dir /s/a/b setup.inf 2>nul
- POPD
- if exist PETOOLS_REG.LST for /f "usebackq delims=" %%i in (PETOOLS_REG.LST) do REGEDIT /S "%%i"
- if exist PETOOLS_INF.lst for /f "usebackq delims=" %%i in (PETOOLS_INF.lst) do RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection DefaultInstall 128 %%i
- IF EXIST PETOOLS_SETUP.LST for /f "usebackq delims=" %%i in (PETOOLS_SETUP.LST) do CALL :PETOOLS_SETUP "%%i"
- DEL petools_*.lst
- POPD
- goto :eof
- :MAKE_LINK
- SETLOCAL
- if "%~1"=="" goto :eof
- if /i "%~n1"=="setup" (
- echo.%%i >>PETOOLS_SETUP.LST
- goto :eof
- )
- SET ".=%~1"
- SET ".=%.:&=^&%"
- SET "PETOOLS=%~dpn1"
- call,SET "PETOOLS=%%PETOOLS:%BASE_DIR%=%外置程序%%%"
- SET "PETOOLS=%PETOOLS:&=^&%"
- echo.LINK %PETOOLS%,%.%>>PETOOLS_LNK.INI
- GOTO :EOF
- :PETOOLS_SETUP
- pushd "%~dp1"
- call %~nx1
- POPD
- goto :eof
chenall发表于: 2009-12-22 13:21
第三版来了,处理了一下快捷方式的合并,解决临时文件冲突的问题(#15).
- ::petools扩展目录搜索安装程序 by chenall [url=http://www.chenall.comhttp://www.chenall.com[/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来调用.以免重复执行
- ::具体无忧专贴:http://bbs.wuyou.net/forum.php?mod=viewthread&tid=158014
- @echo off
- if "%~1"=="" goto :eof
- if not defined StartMenu goto :eof
- if "%~1"=="merge" goto :merge
- if not exist "%~1" goto :eof
- SET "BASE_DIR=%~1"
- SET "外置程序=外置程序_%~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 *.cmd *.bat *.exe readme*.txt 使用说明*.txt
- 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
- 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
chenall 发表于: 2009-12-22 20:07
[ 本帖最后由 chenall 于 2010-3-3 23:14 编辑 ] |
评分
-
查看全部评分
|