当前位置: 首页 > news >正文

批量添加文件夹内exe防火墙规则(禁止出站)

环境

win10
PowerShell

场景

完全不想联网的工具型软件

原理

高级安全Windows Defender防火墙设置出站规则(直接禁止向外发送请求,达到禁网的目的)

过程

  1. 创建 PowerShell 脚本 wall.ps1
点击查看代码
# SCRIPT: Batch create firewall rules to block all EXEs in a folder.# --- Script Body ---# Prompt the user to enter a folder path
$folderPath = Read-Host "Please enter the full folder path to block and press Enter"# Check if the path provided by the user exists
if (-not (Test-Path $folderPath)) {Write-Host "ERROR: The folder path '$folderPath' does not exist or is invalid." -ForegroundColor RedRead-Host "Press Enter to exit."return
}$ruleNamePrefix = "Block EXEs in Folder" 
Write-Host "Searching for all .exe files in '$folderPath' and its subfolders..." -ForegroundColor Cyan# Get all .exe files in the specified folder and all its subfolders
$exeFiles = Get-ChildItem -Path $folderPath -Filter "*.exe" -Recurseif ($exeFiles.Count -eq 0) {Write-Host "No .exe files were found in this folder." -ForegroundColor YellowRead-Host "Press Enter to exit."return
}# Loop through each .exe and create a firewall rule
foreach ($exe in $exeFiles) {# Sanitize the name for the rule to avoid errors$safeName = ($exe.Name -replace '[^a-zA-Z0-9.-]', '_')$ruleName = "$ruleNamePrefix - $safeName - $(Get-Random)" # Add random number to ensure uniquenessWrite-Host "Creating block rule for $($exe.FullName)..."New-NetFirewallRule -DisplayName $ruleName -Direction Outbound -Program $exe.FullName -Action Block -Enabled True -Profile Any
}Write-Host "SUCCESS! Firewall rules have been created for $($exeFiles.Count) programs." -ForegroundColor Green
Write-Host "You can check them in 'Windows Defender Firewall with Advanced Security' under 'Outbound Rules'."
Read-Host "Press Enter to exit."
  1. 调整 PowerShell 执行策略
    Windows 默认禁止运行脚本,以管理员身份打开PowerShell,执行
点击查看代码
Get-ExecutionPolicy

如果显示的是 Restricted,则需要修改,执行

点击查看代码
Set-ExecutionPolicy RemoteSigned

输入 Y 然后按回车确认
3. 执行脚本
可以在 PowerShell 中直接执行

点击查看代码
.\wall.ps1
或者右键脚本文件后点击使用 PowerShell 运行

image

效果

禁用了360文件夹的联网功能
image

http://www.jsqmd.com/news/55120/

相关文章:

  • Asp.net证书配置
  • 【AI白皮书】AI应用开发框架
  • 2025年哈尔滨舒适家居设备服务商TOP5推荐:盛通舒适+基
  • 最小的K个数
  • 2025年南京、武汉、杭州、合肥、福州资质齐全的美团点评代运
  • 2025年锌钢阳台护栏订做厂家权威推荐榜单:不锈钢锌钢护栏/锌钢防护栏‌/组装锌钢护栏‌源头厂家精选
  • 合并两个排序的链表
  • 成都系统开发软件开发公司推荐 口碑好有实力的软件开发品牌
  • 2025年BIPV防水光伏支架定做厂家权威推荐榜单:BIPV楼面光伏支架/BIPV光伏支架‌/BIPV建筑光伏支架‌源头厂家精选
  • 和为S的两个数字
  • 链表中倒数第k个结点
  • PbRL | 近两年论文阅读的不完全总结
  • 二叉树的深度
  • 2025年北京离婚诉讼服务机构排名:离婚诉讼服务哪家可靠/专
  • 效果-生成组
  • 5-5 堆中的路径 (25分)
  • 【设计模式笔记10】:简单工厂模式示例 - 详解
  • 2025年衡水高性价比婚恋介绍服务优选排行榜,婚恋介绍哪家性
  • 5-11 关键活动 (30分)
  • 实用指南:论多数据源集成的应用与实现
  • 5-4 是否同一棵二叉搜索树 (25分)
  • 2025年复合肽饮正品公司权威推荐榜单:瘦身复合肽饮品/沙棘肽复合饮品‌/复合肽饮品测评‌源头公司精选
  • Java/Spring/Dubbo三种SPI机制,到底谁更好?
  • 5-7 六度空间 (30分)
  • 2025年衡水口碑不错的高性价比婚恋介绍专业企业排行榜,婚恋
  • nginx限流
  • 2025年稳定性法兰工厂权威推荐榜单:钢衬活套法兰/一体法兰‌/PPH法兰‌源头工厂精选
  • 5-3 树的同构 (25分)
  • 2025西安网站建设公司推荐3家口碑好的网站制作公司
  • 2025年高性价比超高频感应加热设备供应商排行榜,值得推荐的