个人小站

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 31|回复: 0

自动安装脚本2款

[复制链接]
  • 打卡等级:热心大叔
  • 打卡总天数:348
  • 打卡月天数:2
  • 打卡总奖励:127963
  • 最近打卡:2024-09-12 09:49:55

69

主题

14

回帖

11万

积分

超级版主

Rank: 8Rank: 8

积分
111717

优秀版主论坛元老

发表于 2024-8-19 15:23:23 | 显示全部楼层 |阅读模式
本帖最后由 荣誉会员 于 2024-8-19 15:53 编辑

一、如果文件没有下载,使用此代码

@echo off
setlocal EnableDelayedExpansion

set "installDir=C:\Program Files"  // 软件安装目录
set "downloads=C:\Downloads"  // 下载目录

:menu
cls
echo 请选择要安装的软件:
echo [1] QQ
echo [2] 微信
echo [3] Chrome
echo [4] 退出
set /p choice=

if "%choice%"=="1" (
  set "url=http://dldir1.qq.com/qqfile/qq/QQ9.2.1/25329/QQ9.2.1.25329.exe"
  set "installPath=QQ"
  goto download
) else if "%choice%"=="2" (
  set "url=https://dldir1.qq.com/weixin/Windows/WeChatSetup.exe"
  set "installPath=WeChat"
  goto download
) else if "%choice%"=="3" (
  set "url=https://dl.google.com/chrome/install/standalone/ChromeStandaloneSetup.exe"
  set "installPath=Chrome"
  goto download
) else if "%choice%"=="4" (
  goto end
) else (
  echo 请选择正确的选项!
  pause
  goto menu
)

:download
echo 正在下载 %installPath%...
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%url%', '%downloads%\%installPath%.exe')"
echo 下载完成!
echo.
echo 正在安装 %installPath%...
mkdir "%installDir%\%installPath%"
start /wait "%downloads%\%installPath%.exe" /S /D="%installDir%\%installPath%"
echo.
echo 安装完成!
echo.

:cleanup
echo 正在清理 %installPath%...
del "%downloads%\%installPath%.exe"
del "%appdata%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\%installPath%.lnk"
echo 清理完成!
echo.

pause
goto menu

:end

解释:

第 3 行 setlocal EnableDelayedExpansion 是为了启用变量延迟扩展,这样在 if 语句中使用变量才能正确展开。
第 5 行 set "installDir=C:\Program Files" 是设置软件安装目录,你可以根据需要进行修改。
第 6 行 set "downloads=C:\Downloads" 是设置下载目录,你可以根据需要进行修改。
第 8-20 行是菜单部分,用于选择要安装的软件。
22-32 行是下载部分,根据选择的软件确定下载地址和安装路径,然后使用 PowerShell 的 DownloadFile 方法下载软件到下载目录。
34-40 行是安装部分,创建软件安装目录,并使用 start /wait 命令运行安装程序,安装完成后会提示。
42-49 行是清理部分,删除下载的安装程序和快捷方式。
51-53 行是退出部分,结束批处理程序。


一般情况下 /S 就是静默安装的参数项
二、如果文件已经下载,使用此代码
  1. @echo off
  2. title Auto Install
  3. color 1F
  4. ::企业微信
  5. echo.
  6. start /wait D:\需要软件(win)\WXWork.exe
  7. if %errorlevel%==0 (echo企业微信 安装 ## OK) else (echo 企业微信 安装 ## error)

  8. ::BD杀毒软件
  9. echo.
  10. start /wait D:\需要软件(win)\epskit_x64\epskit_x64.exe
  11. if %errorlevel%==0 (echo BD杀毒软件 安装 ## OK) else (echo BD杀毒软件 安装 ## error)

  12. ::腾讯会议
  13. echo.
  14. start /wait D:\需要软件(win)\TencentMeeting.exe /S
  15. if %errorlevel%==0 (echo 腾讯会议 安装 ## OK) else (echo 腾讯会议 安装 ## error)

  16. ::360压缩
  17. echo.
  18. start /wait D:\需要软件(win)\360zip_setup.exe /S
  19. if %errorlevel%==0 (echo 360压缩 安装 ## OK) else (echo 360压缩 安装 ## error)

  20. ::微信
  21. echo.
  22. start /wait D:\需要软件(win)\WeChatSetup.exe  /S
  23. if %errorlevel%==0 (echo 微信 安装 ## OK) else (echo  微信 安装 ## error)

  24. ::foxmail邮箱
  25. echo.
  26. start /wait D:\需要软件(win)\FoxmailSetup.exe
  27. if %errorlevel%==0 (echo foxmail 安装 ## OK) else (echo foxmail 安装l ## error)

  28. ::telegram安装
  29. echo.
  30. start /wait D:\需要软件(win)\tsetup.exe  /S
  31. if %errorlevel%==0 (echo telegram 安装 ## OK) else (echo telegram 安装 ## error)

  32. ::WPS安装
  33. echo.
  34. start /wait D:\需要软件(win)\W.P.S.exe  /S
  35. if %errorlevel%==0 (echo WPS 安装 ## OK) else (echo WPS 安装 ## error)

  36. ::WhatsAppSetup安装
  37. echo.
  38. start /wait D:\需要软件(win)\WhatsAppSetup.exe  /S
  39. if %errorlevel%==0 (echo WhatsAppSetup 安装 ## OK) else (echo WhatsAppSetup 安装 ## error)

  40. ::谷歌浏览器安装
  41. echo.
  42. start /wait D:\需要软件(win)\chrome.exe  /S
  43. if %errorlevel%==0 (echo 谷歌浏览器 安装 ## OK) else (echo 谷歌浏览器 安装 ## error)

  44. ::ZoomInstaller安装
  45. echo.
  46. start /wait D:\需要软件(win)\ZoomInstaller.exe  /S
  47. if %errorlevel%==0 (echo ZoomInstaller 安装 ## OK) else (echo ZoomInstaller 安装 ## error)
复制代码



PS:  一般情况下 /S 就是静默安装的参数项


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|个人小站

GMT+8, 2024-9-19 09:10 , Processed in 0.027712 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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