Skip to content

Commit

Permalink
添加脚本对proxy的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
NEANC committed Aug 15, 2024
1 parent 81ae290 commit 0df227f
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 5 deletions.
28 changes: 23 additions & 5 deletions Software_Install_Script/software_install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ REM

title 基于 Winget 包管理器的自动化安装脚本

REM chcp 65001 设置编码,防止乱码

ECHO.
ECHO 请注意,安装脚本会进行以下操作:申请管理员权限,更换 Winget 列表源,并在安装结束后重置 Winget 列表源。
ECHO 若同意,请按任意键继续......
ECHO 若同意,请按任意键继续
pause > nul

REM 提权命令
Expand All @@ -26,10 +28,26 @@ REM
winget source remove winget
winget source add winget https://mirrors.ustc.edu.cn/winget-source

REM 逐行读取软件列表文件并安装软件
for /f "tokens=*" %%a in (software_list.txt) do (
echo 正在安装: %%a
winget install %%a
tasklist | find /i "v2rayN.exe" >nul
if %errorlevel% EQU 0 (
ECHO 发现 v2rayN 正在运行,正在申请使用代理进行下载
ECHO 若同意使用代理,请按任意键继续。
pause > nul

rem 设置winget代理配置
winget settings --enable ProxyCommandLineOptions

rem 逐行读取软件列表文件并安装软件,且推荐http代理地址
for /f "tokens=*" %%a in (software_list.txt) do (
echo 正在安装: %%a
winget install %%a --proxy http://127.0.0.1:10809
)
) else (
rem 逐行读取软件列表文件并安装软件
for /f "tokens=*" %%a in (software_list.txt) do (
echo 正在安装: %%a
winget install %%a
)
)

REM 重置列表源 为 官方源
Expand Down
25 changes: 25 additions & 0 deletions Software_Install_Script/text utf8.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@echo off
chcp 65001
set "software=v2rayN.exe"

%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
cd /d "%~dp0"

tasklist | find /i "v2rayN.exe" >nul
if %errorlevel% EQU 0 (
echo v2rayN 正在运行,正在进行下一步

rem 设置winget代理配置
winget settings --enable ProxyCommandLineOptions

rem 逐行读取软件列表文件并安装软件
for /f "tokens=*" %%a in (software_list.txt) do (
echo 正在安装: %%a
winget install %%a --proxy http://127.0.0.1:10809
)
) else (
echo 错误:v2rayN 没有运行,请按任意键退出。
pause > nul
exit /b
)
pause
27 changes: 27 additions & 0 deletions Software_Install_Script/text.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
rem @echo off

rem chcp 65001
set "software=v2rayN.exe"

%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
cd /d "%~dp0"

tasklist | find /i "v2rayN.exe" >nul
if %errorlevel% EQU 0 (
echo v2rayN 正在运行,正在进行下一步

rem 设置winget代理配置
winget settings --enable ProxyCommandLineOptions

rem 逐行读取软件列表文件并安装软件
for /f "tokens=*" %%a in (software_list.txt) do (
echo 正在安装: %%a
winget install %%a --proxy http://127.0.0.1:10809
)
) else (
for /f "tokens=*" %%a in (software_list.txt) do (
echo 正在安装: %%a
winget install %%a
)
)
pause
38 changes: 38 additions & 0 deletions Software_Install_Script/验证ai生成 2.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@echo off
set "software=v2rayN.exe"

rem 检查winget是否存在
where winget >nul
if %errorlevel% NEQ 0 (
echo winget is not installed or not in the PATH. Please install it.
exit /b 1
)

rem 读取代理配置
set "proxy=http://127.0.0.1:10809"
rem 如果需要可以通过环境变量或配置文件来设置代理
rem set "proxy=%PROXY%"

tasklist | find /i "%software%" >nul
if %errorlevel% EQU 0 (
echo %software% is running.

rem 设置winget代理配置
winget settings --enable ProxyCommandLineOptions
if %errorlevel% NEQ 0 (
echo Failed to enable winget proxy settings.
exit /b 1
)

rem 逐行读取软件列表文件并安装软件
for /f "tokens=*" %%a in (software_list.txt) do (
echo 正在安装: %%a
winget install %%a --proxy %proxy%
if %errorlevel% NEQ 0 (
echo Failed to install %%a
)
)
) else (
echo %software% is not running. Exiting script.
exit /b
)
24 changes: 24 additions & 0 deletions Software_Install_Script/验证ai生成-代理检查.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@echo off
setlocal EnableDelayedExpansion

rem 定义软件列表文件路径
set "proxysoftwarelist=proxy_software_list.txt"

rem 检查文件是否存在
if not exist "%proxysoftware%" (
echo Error: File %proxysoftware% does not exist.
exit /b
)

rem 读取并检查每个软件
for /f "tokens=*" %%s in ("%proxysoftware%") do (
set "software=%%s"
tasklist | find /i "!software!" >nul
if %errorlevel% NEQ 0 (
echo !software! is not running. Exiting script.
exit /b
)
)

echo All required software is running.
rem 这里可以添加更多的命令继续执行
18 changes: 18 additions & 0 deletions Software_Install_Script/验证ai生成.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@echo off
set "software=v2rayN.exe"

tasklist | find /i "%software%" >nul
if %errorlevel% EQU 0 (
echo %software% is running.
rem 这里可以添加更多的命令继续执行
winget settings --enable ProxyCommandLineOptions

REM 逐行读取软件列表文件并安装软件
for /f "tokens=*" %%a in (software_list.txt) do (
echo 正在安装: %%a
winget install %%a --proxy http://127.0.0.1:10809
)
) else (
echo %software% is not running. Exiting script.
exit /b
)

0 comments on commit 0df227f

Please sign in to comment.