From e0a7270029fa160ae621d2f77f1609b586965500 Mon Sep 17 00:00:00 2001 From: yxnan Date: Sun, 3 Dec 2023 10:17:11 +0800 Subject: [PATCH] ps1 self elevate --- README.md | 2 +- build-rpglist.sh | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 316c17d..bbe0f08 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ 下列两种方法任选其一: -1. Release获取`BlockRpg.ps1`,使用管理员权限执行即可 +1. Release获取`BlockRpg.ps1`,右键使用Powershell执行,如果有提示需要确认,输入R然后回车即可 2. Release获取`rpglist.json`,导入火绒或者其他类似能提供IP过滤名单的软件即可 ### Linux diff --git a/build-rpglist.sh b/build-rpglist.sh index 20ffd77..c1e0cf4 100755 --- a/build-rpglist.sh +++ b/build-rpglist.sh @@ -68,6 +68,11 @@ iplist_ps1=$(cat rpglist.json | jq --raw-output ' ') echo ' +if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { + Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs + exit +} + $rulename = "Block L4D2 RPG Servers" $iplist = @("'"$iplist_ps1"'") @@ -86,7 +91,7 @@ if ( Get-NetFirewallRule -DisplayName $rulename 2>$null ) { -RemoteAddress $iplist } -echo "Done." +echo "------------- Done. -------------" ' \ > BlockRpg.ps1