本帖最后由 9zhmke 于 2016-1-5 08:58 编辑
我多年前做的批处理版的,只能针对存放绿色软件的文件夹使用,否则自己修改下吧:- @echo off&color 1f
- echo.
- echo ╭─────────────────────────────────────╮
- echo │ │
- echo │ 批量跑快捷.cmd 9z更新于2009.12.1 http://693985.qzone.qq.com │
- echo │ │
- echo │ 目的: 自动查找出文件夹下所有子文件夹里的快捷方式并建立到到桌面,是绿色软 │
- echo │ 件爱好者和电脑公司必备工具, 经常整理软件的个人用户使用起来更是方便。 │
- echo │ │
- echo │ 使用方法: 把所需要处理的文件夹拖到这个程序上面,或者把程序放到文件夹中执 │
- echo │ 行,在桌面或c:\运行时会从G盘到D盘选择最近的一个\tools文件夹处理 │
- echo │ 要求: 1. 用户事先把需建快捷方式的软件在相应目录中都建立一次快捷方式,如 │
- echo │ 果今后这个目录被更改了位置,批处理将自动更正生成新的快捷方式。 │
- echo │ 2. 用户对要注册绿化类的软件建立名字要包含有“注册、绿化、安装、汉 │
- echo │ 化、设置、破解”字样的批处理、执行文件或注册表文件。 │
- echo │ 3. 对不需要建立快捷方式而又要运行的注册表、程序、批处理请更名包含 │
- echo │ 为“关联”字样。 │
- echo │ │
- echo ╰─────────────────────────────────────╯
- setlocal enabledelayedexpansion
- set debug=0
-
- echo Set WS = WScript.CreateObject("WScript.Shell")>d:\temp.vbs
- echo strFullPath ="HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders">>d:\temp.vbs
- echo strNames = "AppData,Personal,Favorites,Desktop">>d:\temp.vbs
- echo aName = Split(strNames, ",")>>d:\temp.vbs
- echo For i = 1 To UBound(aName)>>d:\temp.vbs
- echo Wscript.Echo WS.RegRead(strFullPath ^& "\" ^& aName(i))>>d:\temp.vbs
- echo Next>>d:\temp.vbs
- set n=0
- for /f "delims=" %%i in ('cscript.exe //nologo d:\temp.vbs') do set /a n=n+1&set tmp!n!=%%i
- echo 我的文档=%tmp1%,桌面=%tmp3%
- set desk=%tmp3%
- del d:\temp.vbs >nul 2>nul
- rem 前面几句找桌面,后面这段找工作文件夹
- set doc=%1
- if not "%1"=="" set doc=%doc:"=%
- if "%doc%" gtr "" set filetmp="%1" & cd /d %1&&set i=1
- if /i "%cd%" neq "c:\" if /i "%cd%" neq "%desk%" for /f %%j in ('dir /a:d /b') do set /a i+=1&if "!i!" gtr "2" goto NEXT
- for %%i in (d e f g h i j k l m n o p q r s t u c) do for /f "tokens=3" %%j in ('fsutil fsinfo drivetype %%i:') do (
- if "%%j"=="固定驱动器" if exist %%i:\tools\nul set lastdrv=%%i:
- )
- cd /d %lastdrv%\tools >nul 2>nul && goto NEXT
- :NEXT
- set filetmp=%cd%
- for /d %%i in (*.*) do if exist %%i\nul goto BEGIN
- echo 使用时请把本文件放到相应文件夹里运行或拖动绿色软件的总文件夹到本程序上。
- echo 既没给出指定文件夹,也没找到名为tools的文件夹,程序退出。
- goto END
- :BEGIN
- del d:\temp.tmp /f /q >nul 2>nul
- echo 将对%cd%进行处理,否则请关闭本窗口....
- echo.
- set bakcuppath=%cd%
- cd /d %filetmp%
- echo 请耐心等待,硬盘灯亮完开始闪烁时就快了,程序将把%cd%下子目录里的快捷方式修
- echo 正并全放到桌面,同时查找同级文件夹是否有安装脚本,如果有的话会自动安装...
- echo ===============================================================================
- echo.
- for /f "tokens=1* delims=" %%i in ('dir *.lnk /s /b') do (
- set str="%%i"& call :chklnk "%%i"
- if not "!j!"=="not" (
- set j=!fileurl:快捷方式=!
- set j=!j:.exe=!
- if "!fileurl!" neq "!j!" if exist "%desk%\!j!" del "%desk%\!j!"
- if %debug%==1 echo 如果"!fileurl!" 不等于 "!j!" 那么如果存在 "%desk%\!j!" 删除 "%desk%\!j!"
- ren "%desk%\!fileurl!" "!j!"
- if %debug%==1 echo 改名"%desk%\!fileurl!"为"!j!"
- set fileurl=
- for %%k in (reg,install,setup,启用,破解,汉化,配置,设置,注册,初始,绿化,安装) do (
- for /f %%l in ('dir *%%k*.inf *%%k*.reg *%%k*.exe *%%k*.cmd *%%k*.bat /b 2^>nul') do (
- set str=%%l
- set str=!str:un=!
- set str=!str:卸=!
- set str=!str:删=!
- set str=!str:反=!
- if "!str!" == "%%l" set fileurl=%%l)
- )
- )
- if not "!fileurl!"=="" (if not !fileurl:~-3!==lnk! call :green)
- )
- )
- :关联
- echo.
- echo 快捷方式建立完毕,开始关联文件,有关联字样的程序将不把快捷方式发送到桌面...
- echo ===============================================================================
- cd /d %bakcuppath%
- for /f "delims=" %%i in ('dir *关联*.exe *关联*.bat *关联*.reg *关联*.cmd *关连*.exe *关连*.bat *关连*.reg *关连*.cmd /s /b') do (
- set filetmp=%%~nxi&&set j=
- if %debug%==1 echo 上面一句取得tools下每一文件快捷方式文件路径+文件名,路径=%%~dpi,文件名=%%~nxi
- cd "%%~dpi"
- if "!filetmp:原=!" gtr "!filetmp!" (set filetmp=) else (if "!filetmp:卸=!" gtr "!filetmp!" set filetmp=)
- if "!filetmp!" gtr "" echo ..!cd!\"!filetmp!"&&if /i "!filetmp:~-3!"=="reg" (call regedit /s !filetmp!
- ) else (if /i "!filetmp:~-3!"=="exe" (start /b "" "!cd!\!filetmp!") else (
- ren "^!!filetmp!" "!filetmp!" > nul 1>nul 2>nul &&更名去掉“!”
- echo @echo off >d:\temp.tmp
- type !filetmp!|find /i /v "pause" >>d:\temp.tmp && rem 去掉文件中的pause、exit(以后改为exit /b)不退出cmd.exe
- type d:\temp.tmp|find /i /v "exit" >tmp.bat
- set filetmp="!cd!"
- call tmp.bat
- cd /d !filetmp!&&del tmp.bat&&color 1f&&echo off
- )
- )
- )
- echo.
- echo ================================批量跑快捷已完成工作===========================
- echo ===============================================================================
- echo.
- :MENU
- echo 将把桌面上的快捷方式整理到开始菜单中...
- echo.
- echo.
- rem 取开始菜单位置
- if exist %windir%\repair\*.bat set startmenu=D:\我的文档\系统设置\开始菜单
- if not exist %windir%\repair\*.bat set startmenu=%allusersprofile%\「开始」菜单
- echo.%startmenu%..专业程序..休闲娱乐..常用工具
- echo.
- md "%startmenu%\专业程序" 2>nul
- md "%startmenu%\休闲娱乐" 2>nul
- md "%startmenu%\常用工具" 2>nul
-
- echo.|set /p=直接显示到开始菜单上部的,<nul
- del "%startmenu%\qq*.lnk" /q /f >nul 2>nul
- del "%startmenu%\迅雷*.lnk" /q /f >nul 2>nul
- del "%startmenu%\Thunder*.lnk" /q /f >nul 2>nul
- for %%i in (qq,迅雷,Thunder,连接,车) do move "%desk%\*%%i*.lnk" "%startmenu%">nul 2>nul
- for %%i in (qq,迅雷,Thunder,连接,车) do move "%userprofile%\桌面\*%%i*.lnk" "%startmenu%">nul 2>nul
- for %%i in (qq,迅雷,Thunder,连接,车) do move "%allusersprofile%\桌面\*%%i*.lnk" "%startmenu%">nul 2>nul
-
- echo.|set /p=休闲娱乐类、<nul
- for %%i in (音,听,声,影,视,play,棋,游戏,牌,麻将,vod,播,战,acdsee,斗地主,图,spider) do move "%desk%\*%%i*.lnk" "%startmenu%\休闲娱乐">nul 2>nul
- for %%i in (音,听,声,影,视,play,棋,游戏,牌,麻将,vod,播,战,acdsee,斗地主,图,spider) do move "%userprofile%\桌面\*%%i*.lnk" "%startmenu%\休闲娱乐">nul 2>nul
- for %%i in (音,听,声,影,视,play,棋,游戏,牌,麻将,vod,播,战,acdsee,斗地主,图,spider) do move "%allusersprofile%\桌面\*%%i*.lnk" "%startmenu%\休闲娱乐">nul 2>nul
-
- echo.|set /p=工具类、<nul
- for %%i in (下载,cad,flash,fox,nero,7z,vpc,iso,排版,辞典,译,3d,ocr,conver,pdf,精灵,光驱,旺旺,photoshop,read,dict,UniversalView,wps) do move "%desk%\*%%i*.lnk" "%startmenu%\常用工具">nul 2>nul
- for %%i in (下载,cad,flash,fox,nero,7z,vpc,iso,排版,辞典,译,3d,ocr,conver,pdf,精灵,光驱,旺旺,photoshop,read,dict,UniversalView,wps) do move "%userprofile%\桌面\*%%i*.lnk" "%startmenu%\常用工具">nul 2>nul
- for %%i in (下载,cad,flash,fox,nero,7z,vpc,iso,排版,辞典,译,3d,ocr,conver,pdf,精灵,光驱,旺旺,photoshop,read,dict,UniversalView,wps) do move "%allusersprofile%\桌面\*%%i*.lnk" "%startmenu%\常用工具">nul 2>nul
-
- for %%i in (office,excel,sql,word,powerp,纳米,dutool,资料,阿里旺旺,trstec,raysource,手机,摄,助手,fetion) do move "%desk%\*%%i*.lnk" "%startmenu%\常用工具">nul 2>nul
- for %%i in (office,excel,sql,word,powerp,纳米,dutool,资料,阿里旺旺,trstec,raysource,手机,摄,助手,fetion) do move "%userprofile%\桌面\*%%i*.lnk" "%startmenu%\常用工具">nul 2>nul
- for %%i in (office,excel,sql,word,powerp,纳米,dutool,资料,阿里旺旺,trstec,raysource,手机,摄,助手,fetion) do move "%allusersprofile%\桌面\*%%i*.lnk" "%startmenu%\常用工具">nul 2>nul
-
- echo 专业程序类。
- for %%i in (优化,兔子,整理,拟,360,safe,kv,av,Ulead,毒霸,瑞星,江民,ghost,一键,强力卸载,内存,磁盘,硬盘,安全,量产,U盘,速度,驱动) do move "%desk%\*%%i*.lnk" "%startmenu%\专业程序">nul 2>nul
- for %%i in (优化,兔子,整理,拟,360,safe,kv,av,Ulead,毒霸,瑞星,江民,ghost,一键,强力卸载,内存,磁盘,硬盘,安全,量产,U盘,速度,驱动) do move "%userprofile%\桌面\*%%i*.lnk" "%startmenu%\专业程序">nul 2>nul
- for %%i in (优化,兔子,整理,拟,360,safe,kv,av,Ulead,毒霸,瑞星,江民,ghost,一键,强力卸载,内存,磁盘,硬盘,安全,量产,U盘,速度,驱动) do move "%allusersprofile%\桌面\*%%i*.lnk" "%startmenu%\专业程序">nul 2>nul
-
-
- md "%startmenu%\专业程序\其他"
- for %%i in (进程,mon,icesword,Sys,july,防火墙,SERVICESPE,Tcp,reg,proc,监,注册表,exescope,pecompact,unpack,sysexp,stultima,hex,wpe,警,wingho,还原) do move "%desk%\*%%i*.lnk" "%startmenu%\专业程序\其他">nul 2>nul
- for %%i in (进程,mon,icesword,Sys,july,防火墙,SERVICESPE,Tcp,reg,proc,监,注册表,exescope,pecompact,unpack,sysexp,stultima,hex,wpe,警,wingho,还原) do move "%desk%\*%%i*.lnk" "%userprofile%\桌面\*%%i*.lnk" "%startmenu%\专业程序\其他">nul 2>nul
- for %%i in (进程,mon,icesword,Sys,july,防火墙,SERVICESPE,Tcp,reg,proc,监,注册表,exescope,pecompact,unpack,sysexp,stultima,hex,wpe,警,wingho,还原) do move "%desk%\*%%i*.lnk" "%allusersprofile%\桌面\*%%i*.lnk" "%startmenu%\专业程序\其他">nul 2>nul
-
- :END
- echo.
- del d:\temp.* >nul 2>nul
- cd /d %bakcuppath%
- del tmp.bat /s /q >nul 2>nul
- echo.
- echo.
- echo 批量跑快捷已经完成,请检查开始菜单上部的内容。按任意键退出或直接关闭本窗口....
- pause>nul
- exit
-
- :chklnk
- if %debug%==1 echo 现在的目录是!cd!&pause
- del d:\temp.tmp >nul 2>nul
- set j="%~dp1"
- set filetmp="%~nx1"
- set j=!j:"=!
- set filetmp=!filetmp:"=!
- set fileurl=!filetmp!
- if %debug%==1 echo 传过来的数据是"%~1",取得路径=!j!,文件名=!filetmp!.&pause
- cd "!j!"
- if %debug%==1 echo 进入目录:"!j!",现在的目录是:%cd%
- if %debug%==1 echo --------------
- find /i /c "!j!" "!filetmp!">nul&&echo ..!filetmp!&© "!filetmp!" "%desk%">nul && goto :eof
- if %debug%==1 echo =============
- if %debug%==1 echo 从文件"!filetmp!"里查"!j!"成功则复制"!filetmp!"到"%desk%"完成后返回
- for /f "delims=" %%j in ('find ":" "!filetmp!" ^|findstr /r "^[A-z]:[\\]"') do set i=%%j& set j=%%~nxj
- if %debug%==1 echo 查找快捷方式路径“!i!”+文件名是“!j!”
- if "!i!"=="" echo 无效快捷路径!i!,丢弃.&set j=not& goto :eof
-
- if "!i:~-1!"=="\" (
- if %debug%==1 echo 遇到不同的lnk格式,致使全路径=“!i!”,文件名=“!j!”
- for /f "delims=" %%j in ('find "\" "!filetmp!" ^|findstr /r ".exe"') do set j=%%j
- set i=!i!!j!
- for /f %%j in ('echo !i!') do set j=%%~nxj
- if %debug%==1 echo 修正为全路径=“!i!”,文件名=“!j!”
- )
-
- if exist "!i!" echo .!filetmp!在其它目录里,但是正确的&© "!filetmp!" "%desk%">nul && goto :eof
- if not exist !j! for /f %%j in ('dir !j! /s /a /b') do set j=%%j&echo ..!j!在子目录里&set j=!j:%cd%\=!&echo 去掉前半截为!j!
- if not exist "!j!" echo 无效快捷方式!j!,丢弃.&set j=not& goto :eof
- if %debug%==1 echo 找到!filetmp!,文件是!j!,lnk文件不正确
- echo .LNK路径不对,在桌面另生成:!fileurl!===
- set oldpath="!cd!"
-
- (echo Set WshShell = WScript.CreateObject^("WScript.Shell"^)
- echo strDesktop = WshShell.SpecialFolders^("Desktop"^)
- echo set oShellLink = WshShell.CreateShortcut^(strDesktop ^& "\!fileurl!"^)
- echo oShellLink.TargetPath = "%cd%\!j!" '目标
- echo oShellLink.WindowStyle = 1 '参数1默认窗口激活,参数3最大化激活,参数7最小化
- echo oShellLink.Hotkey = ""
- echo oShellLink.IconLocation = "%cd%\!j!, 0"
- echo oShellLink.Description = ""
- echo oShellLink.WorkingDirectory = "%cd%\"
- echo oShellLink.Save
- )>"d:\temp.vbs"
- cscript.exe //nologo d:\temp.vbs >nul 2>nul
- if %debug%==1 echo !cd!生成了桌面的!fileurl!
- del d:\temp.vbs>nul 2>nul
- if not exist "%desk%\!fileurl!" (
- set fileurl=!fileurl:~0,-4!.url
- if %debug%==1 以下几句生成.url快捷文件
- echo [InternetShortcut]
- echo URL=File:///%cd%\!j!
- echo WorkingDirectory=%cd%
- echo ShowCommand=
- echo IconFile=%cd%\!j!
- echo IconIndex=^0
- echo HotKey=) >"%desk%\!fileurl!"
- if not exist "%desk%\!fileurl!" echo 不知道为什么没有生成桌面快捷方式&goto :eof
- goto :eof
-
- :green
- echo 查找到!fileurl!可能是安装入口
- for %%k in (un,卸,删,反安装) do if "!fileurl:%%k=!" gtr "!fileurl!" set fileurl=
- if %debug%==1 echo 如果!fileurl!里有un,卸,删,反安装,字样则把变量fileurl置空,现在是!fileurl!
- if -!fileurl!-==-- goto :eof
- echo -----找到并注册:!cd!\的"!fileurl!"
- set i=!fileurl:~-3!
- if /i "%i%"=="reg" call regedit /s "!fileurl!" & goto :eof
- if /i "%i%"=="exe" start /b "" "!cd!\!fileurl!" & goto :eof
- if /i "%i%"=="inf" call rundll32 SETUPAPI.DLL,InstallHinfSection DefaultInstall 128 .\!fileurl! & goto :eof
- ren "^!!fileurl!" "!fileurl!" > nul 1>nul 2>nul &&更名去掉“!”
- type !fileurl!|find /i /v "pause" >d:\temp.tmp && rem 去掉文件中的pause,更改exit为exit /b不退出cmd.exe
- echo @echo off >tmp.bat
- type d:\temp.tmp|find /i /v "exit" >>tmp.bat
- call cmd /c tmp.bat
- if %debug%==1 echo 结束时的目录是:“!cd!”老目录是:!oldpath!
- cd /d !oldpath!&&del tmp.bat>nul 2>nul&color 1f&echo off
- goto :eof
复制代码
|