找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 807|回复: 5

[系统相关] [分享讨论] Total Uninstall 6 绿色安装脚本示例

[复制链接]
发表于 2026-1-31 16:08:21 | 显示全部楼层 |阅读模式
示例:
安装目录:X:\Program Files\Total Uninstall 6

脚本位置:X:\Program Files\Setup Total Uninstall 6.cmd
  1. :: 以隐藏方式运行
  2. if "%1" == "hidden" goto begin
  3. mshta vbscript:createobject("wscript.shell").run("""%~nx0"" hidden",0)(window.close)&&exit
  4. :begin

  5. :: 以管理员身份运行
  6. fltmc >nul 2>&1 || PowerShell Start-Process -Verb RunAs -FilePath '%~s0'&&exit /b

  7. :: 检查系统代码页编号
  8. for /f "tokens=2 delims=: " %%i in ('chcp^|findstr ":"') do set Code=%%i
  9. if %Code%==936 (
  10.   set "MwTU=用 Total Uninstall 监视"
  11.   set "Group=Total Uninstall 6"
  12.   set "Program=Tu.exe"
  13.   set "Shortcut=快捷方式(&H)"
  14.   set "Version=6.22.1.505"
  15. )
  16. if %Code%==950 (
  17.   set "MwTU=使用 Total Uninstall 監控"
  18.   set "Group=Total Uninstall 6"
  19.   set "Program=Tu.exe"
  20.   set "Shortcut=捷徑(&H)"
  21.   set "Version=6.22.1.505"
  22. )
  23. if %Code%==437 (
  24.   set "MwTU=Monitor with Total Uninstall"
  25.   set "Group=Total Uninstall 6"
  26.   set "Program=Tu.exe"
  27.   set "Shortcut=S&hortcut"
  28.   set "Version=6.22.1.505"
  29. )
  30. if %Code%==932 (
  31.   set "MwTU=Total Uninstall で監視"
  32.   set "Group=Total Uninstall 6"
  33.   set "Program=Tu.exe"
  34.   set "Shortcut=ショートカット(&H)"
  35.   set "Version=6.22.1.505"
  36. )
  37. if %Code%==949 (
  38.   set "MwTU=Monitor with Total Uninstall"
  39.   set "Group=Total Uninstall 6"
  40.   set "Program=Tu.exe"
  41.   set "Shortcut=S&hortcut"
  42.   set "Version=6.22.1.505"
  43. )

  44. title %Group% %Version% 安装脚本

  45. :: 检查系统版本号
  46. for /f "tokens=4 delims=[.] " %%i in ('ver') do set V=%%i
  47. if %V% leq 5 mshta vbscript:CreateObject("Wscript.Shell").popup("请运行在 Windows XP 及以上系统版本!",4,"提示",64)(window.close)&&exit

  48. cd /d %~dp0

  49. :: 复制文件
  50. for /f "tokens=2*" %%i in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Desktop" ^|findstr "Desktop"') do set "Desktop=%%j"
  51. copy /y "%~dp0%Group%\Program Options.xml" "%Desktop%\%Group%"

  52. :: 添加基本注册表
  53. reg add "HKCR\batfile\shell\TuMonitor" /f /ve /t REG_SZ /d "%MwTU%"
  54. reg add "HKCR\batfile\shell\TuMonitor" /f /v "Icon" /t REG_SZ /d "%~dp0%Group%\%Program%"
  55. reg add "HKCR\batfile\shell\TuMonitor\command" /f /ve /t REG_SZ /d ""%~dp0%Group%\%Program%"  /m"%%1""
  56. reg add "HKCR\exefile\shell\TuMonitor" /f /ve /t REG_SZ /d "%MwTU%"
  57. reg add "HKCR\exefile\shell\TuMonitor" /f /v "Icon" /t REG_SZ /d "%~dp0%Group%\%Program%"
  58. reg add "HKCR\exefile\shell\TuMonitor\command" /f /ve /t REG_SZ /d ""%~dp0%Group%\%Program%" /m"%%1""
  59. reg add "HKCR\Msi.Package\shell\TuMonitor" /f /ve /t REG_SZ /d "%MwTU%"
  60. reg add "HKCR\Msi.Package\shell\TuMonitor" /f /v "Icon" /t REG_SZ /d "%~dp0%Group%\%Program%"
  61. reg add "HKCR\Msi.Package\shell\TuMonitor\command" /f /ve /t REG_SZ /d ""%~dp0%Group%\%Program%" /m"%%1""

  62. :: 创建开始菜单快捷方式
  63. set "P=%APPDATA%\Microsoft\Windows\Start Menu\Programs\%Group%"
  64. md "%P%"
  65. set "N1=%Group%.lnk"
  66. set "D1=%~dp0%Group%\%Program%"
  67. set "A1="
  68. powershell -Command "$ws = New-Object -ComObject WScript.Shell; $s = $ws.CreateShortcut('%P%\%N1%'); $s.TargetPath = '%D1%'; $s.Arguments = '%A1%'; $s.Save()"

  69. :: 创建桌面快捷方式
  70. set "N2=%Group%.lnk"
  71. set "D2=%~dp0%Group%\%Program%"
  72. set "A2="
  73. powershell -Command "$ws = New-Object -ComObject WScript.Shell; $s = $ws.CreateShortcut('%Desktop%\%N2%'); $s.TargetPath = '%D2%'; $s.Arguments = '%A2%'; $s.Save()"

  74. :: 添加上下文快捷方式
  75. if %V% equ 6 (
  76. reg add "HKCR\DesktopBackground\Shell\UpdateInis" /f /v "Icon" /t REG_SZ /d "SHELL32.dll,-040"
  77. reg add "HKCR\DesktopBackground\Shell\UpdateInis" /f /v "MUIVerb" /t REG_SZ /d "%Shortcut%"
  78. reg add "HKCR\DesktopBackground\Shell\UpdateInis" /f /v "Position" /t REG_SZ /d "Bottom"
  79. reg add "HKCR\DesktopBackground\Shell\UpdateInis" /f /v "SubCommands" /t REG_SZ /d ""
  80. reg add "HKCR\DesktopBackground\Shell\UpdateInis\Shell\%Group%" /f /v "Icon" /t REG_SZ /d "%~dp0%Group%\%Program%"
  81. reg add "HKCR\DesktopBackground\Shell\UpdateInis\Shell\%Group%" /f /v "MUIVerb" /t REG_SZ /d "%Group%"
  82. reg add "HKCR\DesktopBackground\Shell\UpdateInis\Shell\%Group%\Command" /f /ve /t REG_SZ /d "%~dp0%Group%\%Program%"
  83. )
复制代码
试了几个隐藏运行的语句,只能用此 3 行才能正常创建到快捷方式!(即代表批处理运行到末尾了)。各位老大有什么看法?
批处理文件必须以 ANSI 编码才能正常运行,所以 %Code%==949 段没办法显示韩语!只能看见 简 繁 英 日。韩用英代替!这个能有办法解决吗?
 楼主| 发表于 2026-1-31 16:19:02 | 显示全部楼层
示例:
安装目录:X:\Program Files\Total Uninstall 6

脚本位置:X:\Program Files\Setup Total Uninstall 6.inf

  1. [Version]
  2. Signature="$CHICAGO$"

  3. [DefaultInstall]
  4. AddReg=AddReg
  5. AddReg=ShortcutMenu
  6. CopyFiles=CopyFiles
  7. UpdateInis=UpdateInis

  8. [DestinationDirs]
  9. CopyFiles=16389        ; X:\Users\Administrator\Documents

  10. [CopyFiles]
  11. Total Uninstall 6\Program Options.xml

  12. [UpdateInis]
  13. Setup.ini,Progman.Groups,,"Desktop=""%16384%"""
  14. Setup.ini,Desktop,,"""%Group%"",""""""%1%\%Group%\%Program%"""""",,,,""%1%\%Group%"",,"""""
  15. %1%\%Group%\Tu.ini,general,,ProgramDataPath=%16389%\%Group%

  16. [AddReg]
  17. HKCR,"batfile\shell\TuMonitor","Icon",,"%1%\%Group%\%Program%"
  18. HKCR,"batfile\shell\TuMonitor",,,"%MwTU%"
  19. HKCR,"batfile\shell\TuMonitor\command",,,"""%1%\%Group%\%Program%""  /m""%%1"""
  20. HKCR,"exefile\shell\TuMonitor","Icon",,"%1%\%Group%\%Program%"
  21. HKCR,"exefile\shell\TuMonitor",,,"%MwTU%"
  22. HKCR,"exefile\shell\TuMonitor\command",,,"""%1%\%Group%\%Program%"" /m""%%1"""
  23. HKCR,"Msi.Package\shell\TuMonitor","Icon",,"%1%\%Group%\%Program%"
  24. HKCR,"Msi.Package\shell\TuMonitor",,,"%MwTU%"
  25. HKCR,"Msi.Package\shell\TuMonitor\command",,,"""%1%\%Group%\%Program%"" /m""%%1"""

  26. [ShortcutMenu]
  27. HKCR,"DesktopBackground\Shell\UpdateInis","Icon",,"SHELL32.dll,-040"
  28. HKCR,"DesktopBackground\Shell\UpdateInis","MUIVerb",,"%Shortcut%"
  29. HKCR,"DesktopBackground\Shell\UpdateInis","Position",,"Bottom"
  30. HKCR,"DesktopBackground\Shell\UpdateInis","SubCommands",,""
  31. HKCR,"DesktopBackground\Shell\UpdateInis\Shell\%Group%","Icon",,"%1%\%Group%\%Program%"
  32. HKCR,"DesktopBackground\Shell\UpdateInis\Shell\%Group%","MUIVerb",,"%Group%"
  33. HKCR,"DesktopBackground\Shell\UpdateInis\Shell\%Group%\Command",,,"%1%\%Group%\%Program%"

  34. [Strings]
  35. MwTU="Monitor with Total Uninstall"
  36. Group=Total Uninstall 6
  37. Program=Tu.exe
  38. Shortcut=S&hortcut
  39. Version=6.22.1.505

  40. [Strings.0804]
  41. MwTU="用 Total Uninstall 监视"
  42. Group=Total Uninstall 6
  43. Program=Tu.exe
  44. Shortcut=快捷方式(&H)
  45. Version=6.22.1.505

  46. [Strings.0404]
  47. MwTU="使用 Total Uninstall 監控"
  48. Group=Total Uninstall 6
  49. Program=Tu.exe
  50. Shortcut=捷徑(&H)
  51. Version=6.22.1.505

  52. [Strings.0411]
  53. MwTU="Total Uninstall で監視"
  54. Group=Total Uninstall 6
  55. Program=Tu.exe
  56. Shortcut=ショートカット(&H)
  57. Version=6.22.1.505

  58. [Strings.0412]
  59. MwTU="Total Uninstall에서 모니터링"
  60. Group=Total Uninstall 6
  61. Program=Tu.exe
  62. Shortcut=바로가기(&H)
  63. Version=6.22.1.505
复制代码
Unicode 编码的 inf 脚本相对 cmd 脚本功能弱了点!因为不能运行某些可执行文件。
 楼主| 发表于 2026-1-31 16:21:54 | 显示全部楼层
本帖最后由 chishingchan 于 2026-1-31 16:23 编辑

inf 版在版本号判断的功能上差了点!也不是不能使用版本号,驱动上是可以的,这里就不清楚!

打算再写一个 VBScript 版!写好再上传。
VBScript 版应该比 cmd 版在功能上可能会更好。
发表于 2026-1-31 19:35:23 | 显示全部楼层
本帖最后由 aloha20200628 于 2026-1-31 19:44 编辑

回复 1# chishingchan

   一。隐藏运行和提权运行可以用 powershell 一行流完成
   二。存为 utf-8 编码的批处脚本中的中英日字面量用 65001 码页可被正常处理,即一楼脚本代码须存为 utf-8 编码,且脚本头部先强制切换为 65001 码页
   据上可订正一楼脚本代码 1-7 行如下:

  1. @echo off
  2. ::提权+隐藏脚本
  3. fltmc>nul 2>nul || (PowerShell -c "start -file '%~f0' -verb runas -win hidden" &exit/b)
  4. ::切换当前码页
  5. chcp 65001>nul
  6. ...脚本其余部分...
复制代码
 楼主| 发表于 2026-1-31 23:35:58 | 显示全部楼层
本帖最后由 chishingchan 于 2026-1-31 23:53 编辑

回复 4# aloha20200628


    这行语句有没有提权不知道,但没有隐藏窗口!
DeepSeek 结果,测试可以:
  1. @echo off
  2. :: 隐藏窗口以管理员身份运行
  3. if "%1"=="hidden" goto :run_as_admin
  4. powershell -Command "Start-Process '%~f0' -ArgumentList 'hidden' -Verb RunAs -WindowStyle Hidden"&&exit /b
  5. :run_as_admin
复制代码
发表于 2026-2-1 20:01:20 | 显示全部楼层
本帖最后由 aloha20200628 于 2026-2-1 20:14 编辑

回复 5# chishingchan

   还是两个问题,一是 '提权+隐藏一行流' 是否成功,我用 win8.1-10 测试以下两个句式均予通过,但二者用法却有区别,用 fltmc>nul 2>nul 是真实测试当前是否为提权状态,而 if "%~1" neq "hide" 则是仅用命令行参数来判断当前是否为提权状态,当然若 Powershell -c ... 运行结果足够可靠,二者是没有区别 ... 由楼主自择吧

  1. fltmc>nul 2>nul || (PowerShell -c "start -file '%~f0' -verb runas -win hidden" &exit/b)
复制代码

  1. if "%~1" neq "hide" (PowerShell -c "start -file '%~f0' -arg "hide" -verb runas -win hidden" &exit/b)
复制代码
第二个问题,是路径文件名包含韩文会导致创建快捷方式 *.lnk 失败,若采用 wscript.shell 方法创建,这确实是一个难过的梗,建议采用快捷方式的另一版本 *.url 以避之,可见如下的示例代码(须用 utf-8 编码存为 test.bat 运行)...

  1. @echo off & chcp 65001>nul
  2. set "uF=%userprofile%\Desktop\计算器ひらがな漢語선생.url"
  3. (for %%s in ("[internetShortCut]", "url=file:///c:\windows\system32\calc.exe") do echo,%%~s)>"%uF%"
  4. exit/b
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 07:06 , Processed in 0.020861 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表