无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站投放广告、加入VIP会员,请联系 微信:wuyouceo
查看: 449|回复: 29
打印 上一主题 下一主题

[分享] 一个 安全中心的 右键菜单(能实时开启和关闭 Win defender实时防护和防篡改)

[复制链接]
跳转到指定楼层
1#
发表于 昨天 16:34 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 qq8899399 于 2025-12-13 21:20 编辑

MDL 论坛 翻到的 一个小软件  原作者项目地址是https://github.com/wesmar/WinDefCtl
核心能力
实时保护控制- 启用/禁用/检查 RTP 状态
防篡改保护控制- 启用/禁用/检查防篡改保护状态
隐蔽执行- 使用 DWM 隐形技术的隐形窗口管理
自动UAC处理- 临时抑制UAC并自动恢复
冷启动检测- 登录后首次运行时的智能预热
可靠的操作确认- 用于 UI 更改的结构密度检测

技术实施
UI自动化API - 无需操作注册表或服务
多层窗口隐藏- 不透明度控制、DWM 隐身、屏幕外定位
智能超时机制- 延长慢速硬件的等待时间(10 秒)
会话感知预热- 用于优化性能的易失性注册表标记
原子操作- 完全成功或自动回滚
UAC恢复系统- 崩溃或中断时自动恢复



对作者PS1 脚本做了修改,支持   
WinDefCtl.ps1 all on 一键启用
WinDefCtl.ps1 all off 一键关闭

使用方法WinDefCtl.ps1和 右键整合的批处理放同一目录 然后运行批处理 进行 右键功能添加和删除


如图  


WinDefCtl脚本如下
  1. #Requires -RunAsAdministrator
  2. # WinDefCtl.ps1 - Windows Defender Automation & Control Utility
  3. # PowerShell Edition - Real-Time Protection and Tamper Protection Management
  4. # Author: Marek Wesolowski - WESMAR - 2025

  5. param(
  6.     [Parameter(Mandatory=$true, Position=0)]
  7.     [ValidateSet('rtp', 'tp', 'all')]
  8.     [string]$Command,
  9.    
  10.     [Parameter(Mandatory=$false, Position=1)]
  11.     [ValidateSet('on', 'off', 'status')]
  12.     [string]$Action = 'status'
  13. )

  14. # ============================================================================
  15. # UI Automation Setup
  16. # ============================================================================

  17. Add-Type -AssemblyName UIAutomationClient
  18. Add-Type -AssemblyName UIAutomationTypes

  19. Add-Type @"
  20. using System;
  21. using System.Runtime.InteropServices;
  22. using System.Text;
  23. public class WinAPI {
  24.     [DllImport("user32.dll")]
  25.     public static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam);
  26.    
  27.     [DllImport("user32.dll")]
  28.     public static extern int GetClassName(IntPtr hWnd, StringBuilder text, int count);
  29.    
  30.     [DllImport("user32.dll")]
  31.     public static extern bool IsWindowVisible(IntPtr hWnd);
  32.    
  33.     [DllImport("user32.dll")]
  34.     public static extern bool SetForegroundWindow(IntPtr hWnd);
  35.    
  36.     [DllImport("user32.dll")]
  37.     public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
  38.    
  39.     [DllImport("user32.dll")]
  40.     public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
  41.    
  42.     [DllImport("user32.dll")]
  43.     public static extern bool IsWindow(IntPtr hWnd);
  44.    
  45.     public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
  46.    
  47.     public const uint WM_SYSCOMMAND = 0x0112;
  48.     public const uint SC_CLOSE = 0xF060;
  49.     public const uint WM_CLOSE = 0x0010;
  50.     public const int SW_SHOWMINNOACTIVE = 7;
  51. }
  52. "@

  53. # ============================================================================
  54. # Registry Helper Functions
  55. # ============================================================================

  56. $UAC_REG_PATH = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"
  57. $VOLATILE_KEY_PATH = "HKCU:\Software\Temp"
  58. $KEY_NOT_EXISTED = 0xFF

  59. function Read-RegistryDword {
  60.     param(
  61.         [string]$Path,
  62.         [string]$Name
  63.     )
  64.    
  65.     try {
  66.         if (Test-Path $Path) {
  67.             $value = Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue
  68.             if ($null -ne $value) {
  69.                 return @{
  70.                     Value = $value.$Name
  71.                     Existed = $true
  72.                 }
  73.             }
  74.         }
  75.     }
  76.     catch { }
  77.    
  78.     return @{
  79.         Value = 0
  80.         Existed = $false
  81.     }
  82. }

  83. function Write-RegistryDword {
  84.     param(
  85.         [string]$Path,
  86.         [string]$Name,
  87.         [int]$Value
  88.     )
  89.    
  90.     try {
  91.         if (-not (Test-Path $Path)) {
  92.             New-Item -Path $Path -Force | Out-Null
  93.         }
  94.         Set-ItemProperty -Path $Path -Name $Name -Value $Value -Type DWord -Force
  95.         return $true
  96.     }
  97.     catch {
  98.         return $false
  99.     }
  100. }

  101. function Remove-RegistryValue {
  102.     param(
  103.         [string]$Path,
  104.         [string]$Name
  105.     )
  106.    
  107.     try {
  108.         if (Test-Path $Path) {
  109.             Remove-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue
  110.         }
  111.         return $true
  112.     }
  113.     catch {
  114.         return $false
  115.     }
  116. }

  117. # ============================================================================
  118. # UAC Management Functions
  119. # ============================================================================

  120. function Encode-UACStatus {
  121.     param(
  122.         [int]$CPBA,
  123.         [bool]$CPBAExisted,
  124.         [int]$POSD,
  125.         [bool]$POSDExisted
  126.     )
  127.    
  128.     $cpbaValue = if ($CPBAExisted) { $CPBA -band 0xFF } else { $KEY_NOT_EXISTED }
  129.     $posdValue = if ($POSDExisted) { $POSD -band 0xFF } else { $KEY_NOT_EXISTED }
  130.    
  131.     $encoded = $cpbaValue -bor ($posdValue -shl 8)
  132.    
  133.     return $encoded
  134. }

  135. function Decode-UACStatus {
  136.     param([int]$Encoded)
  137.    
  138.     $cpbaByte = $Encoded -band 0xFF
  139.     $posdByte = ($Encoded -shr 8) -band 0xFF
  140.    
  141.     return @{
  142.         CPBA = if ($cpbaByte -ne $KEY_NOT_EXISTED) { $cpbaByte } else { 0 }
  143.         CPBAExisted = ($cpbaByte -ne $KEY_NOT_EXISTED)
  144.         POSD = if ($posdByte -ne $KEY_NOT_EXISTED) { $posdByte } else { 0 }
  145.         POSDExisted = ($posdByte -ne $KEY_NOT_EXISTED)
  146.     }
  147. }

  148. function Backup-UAC {
  149.     Write-Host "  [*] Backing up and disabling UAC prompts..."
  150.    
  151.     $cpba = Read-RegistryDword -Path $UAC_REG_PATH -Name "ConsentPromptBehaviorAdmin"
  152.     $posd = Read-RegistryDword -Path $UAC_REG_PATH -Name "PromptOnSecureDesktop"
  153.    
  154.     $encoded = Encode-UACStatus -CPBA $cpba.Value -CPBAExisted $cpba.Existed -POSD $posd.Value -POSDExisted $posd.Existed
  155.    
  156.     if (-not (Write-RegistryDword -Path $UAC_REG_PATH -Name "UACStatus" -Value $encoded)) {
  157.         return $false
  158.     }
  159.    
  160.     $success = $true
  161.     $success = $success -and (Write-RegistryDword -Path $UAC_REG_PATH -Name "ConsentPromptBehaviorAdmin" -Value 0)
  162.     $success = $success -and (Write-RegistryDword -Path $UAC_REG_PATH -Name "PromptOnSecureDesktop" -Value 0)
  163.    
  164.     return $success
  165. }

  166. function Restore-UAC {
  167.     Write-Host "  [*] Restoring original UAC settings..."
  168.    
  169.     $backup = Read-RegistryDword -Path $UAC_REG_PATH -Name "UACStatus"
  170.    
  171.     if (-not $backup.Existed) {
  172.         return $false
  173.     }
  174.    
  175.     $decoded = Decode-UACStatus -Encoded $backup.Value
  176.    
  177.     if ($decoded.CPBAExisted) {
  178.         Write-RegistryDword -Path $UAC_REG_PATH -Name "ConsentPromptBehaviorAdmin" -Value $decoded.CPBA | Out-Null
  179.     }
  180.     else {
  181.         Remove-RegistryValue -Path $UAC_REG_PATH -Name "ConsentPromptBehaviorAdmin" | Out-Null
  182.     }
  183.    
  184.     if ($decoded.POSDExisted) {
  185.         Write-RegistryDword -Path $UAC_REG_PATH -Name "PromptOnSecureDesktop" -Value $decoded.POSD | Out-Null
  186.     }
  187.     else {
  188.         Remove-RegistryValue -Path $UAC_REG_PATH -Name "PromptOnSecureDesktop" | Out-Null
  189.     }
  190.    
  191.     Remove-RegistryValue -Path $UAC_REG_PATH -Name "UACStatus" | Out-Null
  192.     return $true
  193. }

  194. function Test-UACBackupExists {
  195.     $backup = Read-RegistryDword -Path $UAC_REG_PATH -Name "UACStatus"
  196.     return $backup.Existed
  197. }

  198. function Recover-UACIfNeeded {
  199.     if (Test-UACBackupExists) {
  200.         Write-Host "  [RECOVERY] Found incomplete UAC backup, restoring..."
  201.         return Restore-UAC
  202.     }
  203.     return $true
  204. }

  205. # ============================================================================
  206. # Cold Boot Detection (Volatile Registry Marker)
  207. # ============================================================================

  208. function Test-ColdBoot {
  209.     # Volatile key in HKCU:\Software\Temp - disappears on logout/reboot
  210.     try {
  211.         $marker = Get-ItemProperty -Path "$VOLATILE_KEY_PATH" -Name "WinDefCtl_Warmed" -ErrorAction SilentlyContinue
  212.         return ($null -eq $marker)
  213.     }
  214.     catch {
  215.         return $true
  216.     }
  217. }

  218. function Set-WarmMarker {
  219.     try {
  220.         # Create volatile registry key - will disappear on session end
  221.         if (-not (Test-Path $VOLATILE_KEY_PATH)) {
  222.             New-Item -Path $VOLATILE_KEY_PATH -Force | Out-Null
  223.         }
  224.         
  225.         # Unfortunately PowerShell doesn't support REG_OPTION_VOLATILE directly
  226.         # We'll use reg.exe for true volatile key creation
  227.         & reg add "HKCU\Software\Temp" /v "WinDefCtl_Warmed" /t REG_DWORD /d 1 /f | Out-Null
  228.         
  229.         return $true
  230.     }
  231.     catch {
  232.         return $false
  233.     }
  234. }

  235. # ============================================================================
  236. # Window Management Functions
  237. # ============================================================================

  238. function Find-SecurityWindow {
  239.     param([int]$MaxRetries = 10)
  240.    
  241.     $script:foundWindow = $null
  242.    
  243.     for ($i = 0; $i -lt $MaxRetries; $i++) {
  244.         $callback = [WinAPI+EnumWindowsProc] {
  245.             param($hwnd, $lParam)
  246.             
  247.             $className = New-Object System.Text.StringBuilder 256
  248.             [WinAPI]::GetClassName($hwnd, $className, 256) | Out-Null
  249.             
  250.             if ($className.ToString() -eq "ApplicationFrameWindow" -and [WinAPI]::IsWindowVisible($hwnd)) {
  251.                 $script:foundWindow = $hwnd
  252.                 return $false
  253.             }
  254.             return $true
  255.         }
  256.         
  257.         [WinAPI]::EnumWindows($callback, [IntPtr]::Zero) | Out-Null
  258.         
  259.         if ($script:foundWindow) {
  260.             return $script:foundWindow
  261.         }
  262.         
  263.         Start-Sleep -Milliseconds 100
  264.     }
  265.    
  266.     return $null
  267. }

  268. function Close-SecurityWindow {
  269.     param([IntPtr]$WindowHandle)
  270.    
  271.     if ($WindowHandle -eq [IntPtr]::Zero -or -not [WinAPI]::IsWindow($WindowHandle)) {
  272.         return
  273.     }
  274.    
  275.     # Try SetForegroundWindow + SC_CLOSE
  276.     [WinAPI]::SetForegroundWindow($WindowHandle) | Out-Null
  277.     Start-Sleep -Milliseconds 100
  278.     [WinAPI]::SendMessage($WindowHandle, [WinAPI]::WM_SYSCOMMAND, [IntPtr][WinAPI]::SC_CLOSE, [IntPtr]::Zero) | Out-Null
  279.    
  280.     # Wait for window to close
  281.     $closed = $false
  282.     for ($i = 0; $i -lt 30; $i++) {
  283.         if (-not [WinAPI]::IsWindow($WindowHandle)) {
  284.             $closed = $true
  285.             break
  286.         }
  287.         Start-Sleep -Milliseconds 100
  288.     }
  289.    
  290.     # Fallback to WM_CLOSE if needed
  291.     if (-not $closed) {
  292.         [WinAPI]::SendMessage($WindowHandle, [WinAPI]::WM_CLOSE, [IntPtr]::Zero, [IntPtr]::Zero) | Out-Null
  293.         Start-Sleep -Milliseconds 1000
  294.     }
  295. }

  296. # ============================================================================
  297. # Pre-Warming for Cold Boot
  298. # ============================================================================

  299. function Invoke-PreWarmDefender {
  300.     Write-Host "  [*] Cold boot detected - pre-warming Windows Defender..."
  301.    
  302.     Start-Process "windowsdefender://threatsettings" -WindowStyle Hidden
  303.     Start-Sleep -Milliseconds 800
  304.    
  305.     $hwnd = Find-SecurityWindow -MaxRetries 10
  306.    
  307.     if ($hwnd) {
  308.         Write-Host "  [*] Pre-warm window found, waiting for full initialization..."
  309.         Start-Sleep -Milliseconds 800
  310.         
  311.         Write-Host "  [*] Closing pre-warm window..."
  312.         Close-SecurityWindow -WindowHandle $hwnd
  313.         
  314.         Set-WarmMarker | Out-Null
  315.         Write-Host "  [*] Pre-warm complete"
  316.         return $true
  317.     }
  318.    
  319.     Write-Host "  [WARN] Pre-warm window not found, continuing anyway..."
  320.     return $false
  321. }

  322. # ============================================================================
  323. # UI Automation Functions
  324. # ============================================================================

  325. function Wait-UILoaded {
  326.     param(
  327.         [System.Windows.Automation.AutomationElement]$RootElement,
  328.         [int]$MaxRetries = 50
  329.     )
  330.    
  331.     for ($i = 0; $i -lt $MaxRetries; $i++) {
  332.         try {
  333.             $descendants = $RootElement.FindAll(
  334.                 [System.Windows.Automation.TreeScope]::Descendants,
  335.                 [System.Windows.Automation.Condition]::TrueCondition
  336.             )
  337.             
  338.             if ($descendants.Count -gt 10) {
  339.                 return $true
  340.             }
  341.         }
  342.         catch { }
  343.         
  344.         Start-Sleep -Milliseconds 100
  345.     }
  346.    
  347.     return $false
  348. }

  349. function Get-ElementCount {
  350.     param([System.Windows.Automation.AutomationElement]$RootElement)
  351.    
  352.     try {
  353.         $descendants = $RootElement.FindAll(
  354.             [System.Windows.Automation.TreeScope]::Descendants,
  355.             [System.Windows.Automation.Condition]::TrueCondition
  356.         )
  357.         return $descendants.Count
  358.     }
  359.     catch {
  360.         return 0
  361.     }
  362. }

  363. function Wait-StructureChange {
  364.     param(
  365.         [System.Windows.Automation.AutomationElement]$RootElement,
  366.         [int]$BaselineCount,
  367.         [bool]$ExpectIncrease,
  368.         [int]$TimeoutSeconds = 10
  369.     )
  370.    
  371.     Write-Host "  [*] Waiting for UI update..." -NoNewline
  372.     $maxLoops = $TimeoutSeconds * 10
  373.    
  374.     for ($i = 0; $i -lt $maxLoops; $i++) {
  375.         $currentCount = Get-ElementCount -RootElement $RootElement
  376.         
  377.         $structureChanged = if ($ExpectIncrease) {
  378.             $currentCount -gt $BaselineCount
  379.         } else {
  380.             $currentCount -lt $BaselineCount
  381.         }
  382.         
  383.         if ($structureChanged) {
  384.             Start-Sleep -Milliseconds 200
  385.             $recheckCount = Get-ElementCount -RootElement $RootElement
  386.             
  387.             $stable = if ($ExpectIncrease) {
  388.                 $recheckCount -gt $BaselineCount
  389.             } else {
  390.                 $recheckCount -lt $BaselineCount
  391.             }
  392.             
  393.             if ($stable) {
  394.                 Write-Host " [OK]"
  395.                 return $true
  396.             }
  397.         }
  398.         
  399.         Start-Sleep -Milliseconds 100
  400.     }
  401.    
  402.     Write-Host " [WARN] Timeout."
  403.     return $false
  404. }

  405. function Find-FirstToggleSwitch {
  406.     param([System.Windows.Automation.AutomationElement]$RootElement)
  407.    
  408.     $condition = New-Object System.Windows.Automation.PropertyCondition(
  409.         [System.Windows.Automation.AutomationElement]::ControlTypeProperty,
  410.         [System.Windows.Automation.ControlType]::Button
  411.     )
  412.    
  413.     $buttons = $RootElement.FindAll([System.Windows.Automation.TreeScope]::Descendants, $condition)
  414.    
  415.     foreach ($button in $buttons) {
  416.         try {
  417.             $togglePattern = $button.GetCurrentPattern([System.Windows.Automation.TogglePattern]::Pattern)
  418.             if ($togglePattern) {
  419.                 return $button
  420.             }
  421.         }
  422.         catch { }
  423.     }
  424.    
  425.     return $null
  426. }

  427. function Find-LastToggleSwitch {
  428.     param([System.Windows.Automation.AutomationElement]$RootElement)
  429.    
  430.     $condition = New-Object System.Windows.Automation.PropertyCondition(
  431.         [System.Windows.Automation.AutomationElement]::ControlTypeProperty,
  432.         [System.Windows.Automation.ControlType]::Button
  433.     )
  434.    
  435.     $buttons = $RootElement.FindAll([System.Windows.Automation.TreeScope]::Descendants, $condition)
  436.     $lastToggle = $null
  437.    
  438.     foreach ($button in $buttons) {
  439.         try {
  440.             $togglePattern = $button.GetCurrentPattern([System.Windows.Automation.TogglePattern]::Pattern)
  441.             if ($togglePattern) {
  442.                 $lastToggle = $button
  443.             }
  444.         }
  445.         catch { }
  446.     }
  447.    
  448.     return $lastToggle
  449. }

  450. # ============================================================================
  451. # Real-Time Protection Functions
  452. # ============================================================================

  453. function Get-RTPStatus {
  454.     param([System.Windows.Automation.AutomationElement]$RootElement)
  455.    
  456.     $button = Find-FirstToggleSwitch -RootElement $RootElement
  457.     if (-not $button) {
  458.         return $null
  459.     }
  460.    
  461.     try {
  462.         $togglePattern = $button.GetCurrentPattern([System.Windows.Automation.TogglePattern]::Pattern)
  463.         $state = $togglePattern.Current.ToggleState
  464.         $isEnabled = ($state -eq [System.Windows.Automation.ToggleState]::On)
  465.         
  466.         Write-Host "  [*] RTP Status: $(if ($isEnabled) { 'ENABLED' } else { 'DISABLED' })"
  467.         return $isEnabled
  468.     }
  469.     catch {
  470.         return $null
  471.     }
  472. }

  473. function Enable-RTP {
  474.     param([System.Windows.Automation.AutomationElement]$RootElement)
  475.    
  476.     if (-not (Backup-UAC)) {
  477.         return $false
  478.     }
  479.    
  480.     $button = Find-FirstToggleSwitch -RootElement $RootElement
  481.     if (-not $button) {
  482.         Restore-UAC | Out-Null
  483.         return $false
  484.     }
  485.    
  486.     try {
  487.         $togglePattern = $button.GetCurrentPattern([System.Windows.Automation.TogglePattern]::Pattern)
  488.         $state = $togglePattern.Current.ToggleState
  489.         
  490.         if ($state -eq [System.Windows.Automation.ToggleState]::Off) {
  491.             $baseline = Get-ElementCount -RootElement $RootElement
  492.             $togglePattern.Toggle()
  493.             $result = Wait-StructureChange -RootElement $RootElement -BaselineCount $baseline -ExpectIncrease $false
  494.         }
  495.         else {
  496.             Write-Host "  [*] RTP already enabled"
  497.             $result = $true
  498.         }
  499.         
  500.         Restore-UAC | Out-Null
  501.         return $result
  502.     }
  503.     catch {
  504.         Restore-UAC | Out-Null
  505.         return $false
  506.     }
  507. }

  508. function Disable-RTP {
  509.     param([System.Windows.Automation.AutomationElement]$RootElement)
  510.    
  511.     if (-not (Backup-UAC)) {
  512.         return $false
  513.     }
  514.    
  515.     $button = Find-FirstToggleSwitch -RootElement $RootElement
  516.     if (-not $button) {
  517.         Restore-UAC | Out-Null
  518.         return $false
  519.     }
  520.    
  521.     try {
  522.         $togglePattern = $button.GetCurrentPattern([System.Windows.Automation.TogglePattern]::Pattern)
  523.         $state = $togglePattern.Current.ToggleState
  524.         
  525.         if ($state -eq [System.Windows.Automation.ToggleState]::On) {
  526.             $baseline = Get-ElementCount -RootElement $RootElement
  527.             $togglePattern.Toggle()
  528.             $result = Wait-StructureChange -RootElement $RootElement -BaselineCount $baseline -ExpectIncrease $true
  529.         }
  530.         else {
  531.             Write-Host "  [*] RTP already disabled"
  532.             $result = $true
  533.         }
  534.         
  535.         Restore-UAC | Out-Null
  536.         return $result
  537.     }
  538.     catch {
  539.         Restore-UAC | Out-Null
  540.         return $false
  541.     }
  542. }

  543. # ============================================================================
  544. # Tamper Protection Functions
  545. # ============================================================================

  546. function Get-TPStatus {
  547.     param([System.Windows.Automation.AutomationElement]$RootElement)
  548.    
  549.     $button = Find-LastToggleSwitch -RootElement $RootElement
  550.     if (-not $button) {
  551.         return $null
  552.     }
  553.    
  554.     try {
  555.         $togglePattern = $button.GetCurrentPattern([System.Windows.Automation.TogglePattern]::Pattern)
  556.         $state = $togglePattern.Current.ToggleState
  557.         $isEnabled = ($state -eq [System.Windows.Automation.ToggleState]::On)
  558.         
  559.         Write-Host "  [*] Tamper Protection Status: $(if ($isEnabled) { 'ENABLED' } else { 'DISABLED' })"
  560.         return $isEnabled
  561.     }
  562.     catch {
  563.         return $null
  564.     }
  565. }

  566. function Enable-TP {
  567.     param([System.Windows.Automation.AutomationElement]$RootElement)
  568.    
  569.     if (-not (Backup-UAC)) {
  570.         return $false
  571.     }
  572.    
  573.     $button = Find-LastToggleSwitch -RootElement $RootElement
  574.     if (-not $button) {
  575.         Restore-UAC | Out-Null
  576.         return $false
  577.     }
  578.    
  579.     try {
  580.         $togglePattern = $button.GetCurrentPattern([System.Windows.Automation.TogglePattern]::Pattern)
  581.         $state = $togglePattern.Current.ToggleState
  582.         
  583.         if ($state -eq [System.Windows.Automation.ToggleState]::Off) {
  584.             $baseline = Get-ElementCount -RootElement $RootElement
  585.             $togglePattern.Toggle()
  586.             $result = Wait-StructureChange -RootElement $RootElement -BaselineCount $baseline -ExpectIncrease $false
  587.         }
  588.         else {
  589.             Write-Host "  [*] Tamper Protection already enabled"
  590.             $result = $true
  591.         }
  592.         
  593.         Restore-UAC | Out-Null
  594.         return $result
  595.     }
  596.     catch {
  597.         Restore-UAC | Out-Null
  598.         return $false
  599.     }
  600. }

  601. function Disable-TP {
  602.     param([System.Windows.Automation.AutomationElement]$RootElement)
  603.    
  604.     if (-not (Backup-UAC)) {
  605.         return $false
  606.     }
  607.    
  608.     $button = Find-LastToggleSwitch -RootElement $RootElement
  609.     if (-not $button) {
  610.         Restore-UAC | Out-Null
  611.         return $false
  612.     }
  613.    
  614.     try {
  615.         $togglePattern = $button.GetCurrentPattern([System.Windows.Automation.TogglePattern]::Pattern)
  616.         $state = $togglePattern.Current.ToggleState
  617.         
  618.         if ($state -eq [System.Windows.Automation.ToggleState]::On) {
  619.             $baseline = Get-ElementCount -RootElement $RootElement
  620.             $togglePattern.Toggle()
  621.             $result = Wait-StructureChange -RootElement $RootElement -BaselineCount $baseline -ExpectIncrease $true
  622.         }
  623.         else {
  624.             Write-Host "  [*] Tamper Protection already disabled"
  625.             $result = $true
  626.         }
  627.         
  628.         Restore-UAC | Out-Null
  629.         return $result
  630.     }
  631.     catch {
  632.         Restore-UAC | Out-Null
  633.         return $false
  634.     }
  635. }

  636. # ============================================================================
  637. # Process Single Command
  638. # ============================================================================

  639. function Process-SingleCommand {
  640.     param(
  641.         [string]$Cmd,
  642.         [string]$Act
  643.     )
  644.    
  645.     Write-Host ""
  646.     Write-Host "=== Windows Defender $(if ($Cmd -eq 'rtp') { 'RTP' } else { 'Tamper Protection' }) Control ===" -ForegroundColor Cyan
  647.     Write-Host ""

  648.     # Check for incomplete UAC backup from previous crash
  649.     Recover-UACIfNeeded | Out-Null

  650.     Write-Host "  [*] Opening Windows Defender..."

  651.     # Pre-warming on cold boot
  652.     if (Test-ColdBoot) {
  653.         Invoke-PreWarmDefender | Out-Null
  654.         Start-Sleep -Milliseconds 800
  655.     }

  656.     # Open Windows Security
  657.     Start-Process "windowsdefender://threatsettings" -WindowStyle Hidden
  658.     $hwndSecurity = Find-SecurityWindow -MaxRetries 10

  659.     if (-not $hwndSecurity) {
  660.         Write-Host "  [ERROR] Failed to find Windows Security window" -ForegroundColor Red
  661.         return $false
  662.     }

  663.     # Get UI Automation root element
  664.     try {
  665.         $rootElement = [System.Windows.Automation.AutomationElement]::FromHandle($hwndSecurity)
  666.     }
  667.     catch {
  668.         Write-Host "  [ERROR] Failed to get automation element" -ForegroundColor Red
  669.         Close-SecurityWindow -WindowHandle $hwndSecurity
  670.         return $false
  671.     }

  672.     # Wait for UI to load
  673.     if (-not (Wait-UILoaded -RootElement $rootElement -MaxRetries 50)) {
  674.         Write-Host "  [ERROR] Failed to load UI (Timeout on slow system)" -ForegroundColor Red
  675.         Close-SecurityWindow -WindowHandle $hwndSecurity
  676.         return $false
  677.     }

  678.     # Execute requested action
  679.     $result = $false

  680.     if ($Cmd -eq 'rtp') {
  681.         switch ($Act) {
  682.             'status' {
  683.                 $result = (Get-RTPStatus -RootElement $rootElement) -ne $null
  684.             }
  685.             'on' {
  686.                 $result = Enable-RTP -RootElement $rootElement
  687.             }
  688.             'off' {
  689.                 $result = Disable-RTP -RootElement $rootElement
  690.             }
  691.         }
  692.     }
  693.     elseif ($Cmd -eq 'tp') {
  694.         switch ($Act) {
  695.             'status' {
  696.                 $result = (Get-TPStatus -RootElement $rootElement) -ne $null
  697.             }
  698.             'on' {
  699.                 $result = Enable-TP -RootElement $rootElement
  700.             }
  701.             'off' {
  702.                 $result = Disable-TP -RootElement $rootElement
  703.             }
  704.         }
  705.     }

  706.     # Close security window
  707.     Close-SecurityWindow -WindowHandle $hwndSecurity

  708.     return $result
  709. }

  710. # ============================================================================
  711. # Main Execution Flow
  712. # ============================================================================

  713. $overallResult = $true

  714. if ($Command -eq 'all') {
  715.     Write-Host ""
  716.     Write-Host "=== Windows Defender ALL Control ($Action) ===" -ForegroundColor Cyan
  717.     Write-Host ""
  718.    
  719.     if ($Action -eq 'status') {
  720.         # Process RTP status
  721.         $rtpResult = Process-SingleCommand -Cmd 'rtp' -Act 'status'
  722.         
  723.         Write-Host ""
  724.         Write-Host "---" -ForegroundColor DarkGray
  725.         
  726.         # Process TP status
  727.         $tpResult = Process-SingleCommand -Cmd 'tp' -Act 'status'
  728.         
  729.         $overallResult = $rtpResult -and $tpResult
  730.     }
  731.     else {
  732.         # Process RTP action
  733.         Write-Host "[1/2] Processing RTP ($Action)..." -ForegroundColor Cyan
  734.         $rtpResult = Process-SingleCommand -Cmd 'rtp' -Act $Action
  735.         
  736.         Write-Host ""
  737.         Write-Host "--- Waiting 1 second ---" -ForegroundColor DarkGray
  738.         Start-Sleep -Seconds 1
  739.         
  740.         # Process TP action
  741.         Write-Host "[2/2] Processing Tamper Protection ($Action)..." -ForegroundColor Cyan
  742.         $tpResult = Process-SingleCommand -Cmd 'tp' -Act $Action
  743.         
  744.         $overallResult = $rtpResult -and $tpResult
  745.         
  746.         Write-Host ""
  747.         Write-Host "=== Summary ===" -ForegroundColor Cyan
  748.         Write-Host "  [*] RTP ($Action): $(if ($rtpResult) { 'SUCCESS' } else { 'FAILED' })" -ForegroundColor $(if ($rtpResult) { 'Green' } else { 'Red' })
  749.         Write-Host "  [*] Tamper Protection ($Action): $(if ($tpResult) { 'SUCCESS' } else { 'FAILED' })" -ForegroundColor $(if ($tpResult) { 'Green' } else { 'Red' })
  750.     }
  751. }
  752. else {
  753.     $overallResult = Process-SingleCommand -Cmd $Command -Act $Action
  754. }

  755. Write-Host ""
  756. Write-Host "  [*] Operation completed." -ForegroundColor $(if ($overallResult) { 'Green' } else { 'Yellow' })
  757. Write-Host ""

  758. exit $(if ($overallResult) { 0 } else { 1 })
复制代码


整合右键菜单批处理如下
  1. @ECHO OFF
  2. PUSHD %~dp0
  3. TITLE Hello World
  4. >nul reg add hkcu\software\classes\.Admin\shell\runas\command /f /ve /d "cmd /x /d /r set "f0=%%2" &call "%%2" %%3" & set "_= %*"
  5. >nul fltmc || if "%f0%" neq "%~f0" ( cd.>"%tmp%\runas.Admin" & start "%~n0" /high "%tmp%\runas.Admin" "%~f0" "%_:"=""%" &exit /b )


  6. cd /d "%~dp0"
  7. if "%PROCESSOR_ARCHITECTURE%"=="x86" set bits=32
  8. if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set bits=64


  9. REM 检查命令行参数
  10. if "%~1"=="install" (
  11.     goto install
  12. )
  13. if "%~1"=="uninstall" (
  14.     goto uninstall
  15. )

  16. Rem 设置程序路径
  17. SET "_file_path=%~dp0"
  18. Rem 设置命令行
  19. SET "_cmd_cmd_enable=powershell Start-Process cmd -Verb RunAs -ArgumentList '/S /K pushd "%%V" &"%~dp0WinDefCtl.exe" rtp on &"%~dp0WinDefCtl.exe" tp on &exit'"
  20. SET "_cmd_cmd_disabled=powershell Start-Process cmd -Verb RunAs -ArgumentList '/S /K pushd "%%V" &"%~dp0WinDefCtl.exe" rtp off &"%~dp0WinDefCtl.exe" tp off &exit'"
  21. SET "_cmd_scripts_enable="powershell.exe" "-Command" ""& {Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy RemoteSigned -File "%~dp0WinDefCtl.ps1" all on' -Verb RunAs}""
  22. SET "_cmd_scripts_disabled="powershell.exe" "-Command" ""& {Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy RemoteSigned -File "%~dp0WinDefCtl.ps1" all off' -Verb RunAs}""
  23. Rem 设置注册表初始值
  24. SET "_regkey1=HKCR\*\Shell\WindowsSecurity"
  25. SET "_regkey2=HKCR\Directory\Shell\WindowsSecurity"
  26. SET "_regkey3=HKCR\Directory\background\Shell\WindowsSecurity"
  27. SET "_regkey4=HKCR\Drive\Shell\WindowsSecurity"
  28. SET "_regkey5=HKCR\DesktopBackground\Shell\WindowsSecurity"

  29. :Menu
  30. SET Options=
  31. ECHO.&ECHO. 1.安装 WinDefCtl 鼠标右键菜单
  32. ECHO.&ECHO. 2.卸载 WinDefCtl 鼠标右键菜单
  33. ECHO.&ECHO. 3.退出
  34. ECHO.
  35. SET /P Options=请输入选择项目序号并按回车确认:
  36. IF /I "%Options%"=="1" GOTO install
  37. IF /I "%Options%"=="2" GOTO uninstall
  38. IF /I "%Options%"=="3" GOTO OUT
  39. ECHO.&ECHO.序号无效,请重新输入!
  40. PING -n 2 127.1>NUL
  41. CLS
  42. GOTO Menu

  43. :install
  44. REM 删除残留注册项
  45. reg delete "%_regkey1%" /f
  46. for %%i in ("%_regkey2%" "%_regkey3%" "%_regkey4%" "%_regkey5%") do reg delete %%i /f
  47. Rem 单独处理 HKCR\*\Shell\WindowsSecurity(for循环直接导入通配符*会失败)
  48. Reg.exe add "%_regkey1%" /v "Icon" /t REG_SZ /d "%%ProgramFiles%%\Windows Defender\EppManifest.dll,-101" /f
  49. Reg.exe add "%_regkey1%" /v "MUIVerb" /t REG_SZ /d "Windows 安全中心" /f
  50. Reg.exe add "%_regkey1%" /v "Position" /t REG_SZ /d "Bottom" /f
  51. Reg.exe add "%_regkey1%" /v "SubCommands" /t REG_SZ /d "" /f
  52. Reg.exe add "%_regkey1%" /v "SeparatorBefore" /t REG_SZ /d "" /f
  53. Reg.exe add "%_regkey1%" /v "SeparatorAfter" /t REG_SZ /d "" /f
  54. Reg.exe add "%_regkey1%\shell\001flyout" /v "Icon" /t REG_SZ /d "%%ProgramFiles%%\Windows Defender\EppManifest.dll,-101" /f
  55. Reg.exe add "%_regkey1%\shell\001flyout" /v "MUIVerb" /t REG_SZ /d "&安全中心主页" /f
  56. Reg.exe add "%_regkey1%\shell\001flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  57. Reg.exe add "%_regkey1%\shell\001flyout" /v "SeparatorBefore" /t REG_SZ /d "" /f
  58. Reg.exe add "%_regkey1%\shell\001flyout" /v "SeparatorAfter" /t REG_SZ /d "" /f
  59. Reg.exe add "%_regkey1%\shell\001flyout" /v "CommandFlags" /t REG_DWORD /d "64" /f
  60. Reg.exe add "%_regkey1%\shell\001flyout\command" /ve /t REG_SZ /d "explorer windowsdefender:" /f
  61. Reg.exe add "%_regkey1%\shell\002flyout" /v "MUIVerb" /t REG_SZ /d "&病毒和威胁防护" /f
  62. Reg.exe add "%_regkey1%\shell\002flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  63. Reg.exe add "%_regkey1%\shell\002flyout" /v "Position" /t REG_SZ /d "Bottom" /f
  64. Reg.exe add "%_regkey1%\shell\002flyout" /v "SubCommands" /t REG_SZ /d "" /f
  65. Reg.exe add "%_regkey1%\shell\002flyout\shell" /v "SubCommands" /t REG_SZ /d "" /f
  66. Reg.exe add "%_regkey1%\shell\002flyout\shell\001" /v "MUIVerb" /t REG_SZ /d "病毒和威胁防护 设置主页" /f
  67. Reg.exe add "%_regkey1%\shell\002flyout\shell\001" /v "HasLUAShield" /t REG_SZ /d "" /f
  68. Reg.exe add "%_regkey1%\shell\002flyout\shell\001" /v "SeparatorBefore" /t REG_SZ /d "" /f
  69. Reg.exe add "%_regkey1%\shell\002flyout\shell\001" /v "SeparatorAfter" /t REG_SZ /d "" /f
  70. Reg.exe add "%_regkey1%\shell\002flyout\shell\001" /v "CommandFlags" /t REG_DWORD /d "64" /f
  71. Reg.exe add "%_regkey1%\shell\002flyout\shell\001\command" /ve /t REG_SZ /d "explorer windowsdefender://threat" /f
  72. Reg.exe add "%_regkey1%\shell\002flyout\shell\002" /v "MUIVerb" /t REG_SZ /d "启用 实时防护和防篡改" /f
  73. Reg.exe add "%_regkey1%\shell\002flyout\shell\002" /v "HasLUAShield" /t REG_SZ /d "" /f
  74. Reg.exe add "%_regkey1%\shell\002flyout\shell\002\command" /ve /t REG_SZ /d "%_cmd_scripts_enable%" /f
  75. Reg.exe add "%_regkey1%\shell\002flyout\shell\003" /v "MUIVerb" /t REG_SZ /d "禁用 实时防护和防篡改" /f
  76. Reg.exe add "%_regkey1%\shell\002flyout\shell\003" /v "HasLUAShield" /t REG_SZ /d "" /f
  77. Reg.exe add "%_regkey1%\shell\002flyout\shell\003\command" /ve /t REG_SZ /d "%_cmd_scripts_disabled%" /f
  78. Reg.exe add "%_regkey1%\shell\003flyout" /v "MUIVerb" /t REG_SZ /d "&账户保护" /f
  79. Reg.exe add "%_regkey1%\shell\003flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  80. Reg.exe add "%_regkey1%\shell\003flyout\command" /ve /t REG_SZ /d "explorer windowsdefender://account" /f
  81. Reg.exe add "%_regkey1%\shell\004flyout" /v "MUIVerb" /t REG_SZ /d "&防火墙和网络保护" /f
  82. Reg.exe add "%_regkey1%\shell\004flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  83. Reg.exe add "%_regkey1%\shell\004flyout" /v "Position" /t REG_SZ /d "Bottom" /f
  84. Reg.exe add "%_regkey1%\shell\004flyout" /v "SubCommands" /t REG_SZ /d "" /f
  85. Reg.exe add "%_regkey1%\shell\004flyout\shell" /v "SubCommands" /t REG_SZ /d "" /f
  86. Reg.exe add "%_regkey1%\shell\004flyout\shell\001" /v "MUIVerb" /t REG_SZ /d "防火墙和网络保护 设置主页" /f
  87. Reg.exe add "%_regkey1%\shell\004flyout\shell\001" /v "HasLUAShield" /t REG_SZ /d "" /f
  88. Reg.exe add "%_regkey1%\shell\004flyout\shell\001" /v "SeparatorBefore" /t REG_SZ /d "" /f
  89. Reg.exe add "%_regkey1%\shell\004flyout\shell\001" /v "SeparatorAfter" /t REG_SZ /d "" /f
  90. Reg.exe add "%_regkey1%\shell\004flyout\shell\001" /v "CommandFlags" /t REG_DWORD /d "64" /f
  91. Reg.exe add "%_regkey1%\shell\004flyout\shell\001\command" /ve /t REG_SZ /d "explorer windowsdefender://network" /f
  92. Reg.exe add "%_regkey1%\shell\004flyout\shell\002" /v "MUIVerb" /t REG_SZ /d "启用 Windows 防火墙" /f
  93. Reg.exe add "%_regkey1%\shell\004flyout\shell\002" /v "HasLUAShield" /t REG_SZ /d "" /f
  94. Reg.exe add "%_regkey1%\shell\004flyout\shell\002\command" /ve /t REG_SZ /d "powershell.exe -windowstyle hidden -command "Start-Process cmd -ArgumentList '/s,/c,netsh advfirewall set allprofiles state on' -Verb runAs"" /f
  95. Reg.exe add "%_regkey1%\shell\004flyout\shell\003" /v "MUIVerb" /t REG_SZ /d "禁用 Windows 防火墙" /f
  96. Reg.exe add "%_regkey1%\shell\004flyout\shell\003" /v "HasLUAShield" /t REG_SZ /d "" /f
  97. Reg.exe add "%_regkey1%\shell\004flyout\shell\003\command" /ve /t REG_SZ /d "powershell.exe -windowstyle hidden -command "Start-Process cmd -ArgumentList '/s,/c,netsh advfirewall set allprofiles state off' -Verb runAs"" /f
  98. Reg.exe add "%_regkey1%\shell\005flyout" /v "MUIVerb" /t REG_SZ /d "应用和浏览器控制" /f
  99. Reg.exe add "%_regkey1%\shell\005flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  100. Reg.exe add "%_regkey1%\shell\005flyout\command" /ve /t REG_SZ /d "explorer windowsdefender://appbrowser" /f
  101. Reg.exe add "%_regkey1%\shell\006flyout" /v "MUIVerb" /t REG_SZ /d "&设备安全性" /f
  102. Reg.exe add "%_regkey1%\shell\006flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  103. Reg.exe add "%_regkey1%\shell\006flyout\command" /ve /t REG_SZ /d "explorer windowsdefender://devicesecurity" /f
  104. Reg.exe add "%_regkey1%\shell\007flyout" /v "MUIVerb" /t REG_SZ /d "&设备性能和运行状况" /f
  105. Reg.exe add "%_regkey1%\shell\007flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  106. Reg.exe add "%_regkey1%\shell\007flyout\command" /ve /t REG_SZ /d "explorer windowsdefender://perfhealth" /f
  107. Reg.exe add "%_regkey1%\shell\008flyout" /v "MUIVerb" /t REG_SZ /d "&家庭选项" /f
  108. Reg.exe add "%_regkey1%\shell\008flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  109. Reg.exe add "%_regkey1%\shell\008flyout\command" /ve /t REG_SZ /d "explorer windowsdefender://family" /f
  110. Reg.exe add "%_regkey1%\shell\009flyout" /v "MUIVerb" /t REG_SZ /d "&保护历史记录" /f
  111. Reg.exe add "%_regkey1%\shell\009flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  112. Reg.exe add "%_regkey1%\shell\009flyout\command" /ve /t REG_SZ /d "explorer windowsdefender://history" /f
  113. Reg.exe add "%_regkey1%\shell\010flyout" /v "MUIVerb" /t REG_SZ /d "&安全提供程序" /f
  114. Reg.exe add "%_regkey1%\shell\010flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  115. Reg.exe add "%_regkey1%\shell\010flyout\command" /ve /t REG_SZ /d "explorer windowsdefender://providers" /f
  116. Reg.exe add "%_regkey1%\shell\011flyout" /v "MUIVerb" /t REG_SZ /d "&通知" /f
  117. Reg.exe add "%_regkey1%\shell\011flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  118. Reg.exe add "%_regkey1%\shell\011flyout\command" /ve /t REG_SZ /d "explorer windowsdefender://settings" /f
  119. Rem Windows安全中心菜单总项
  120. for %%k in ("%_regkey2%" "%_regkey3%" "%_regkey4%") do (
  121.     Reg.exe add %%k /v "Icon" /t REG_SZ /d "%ProgramFiles%\Windows Defender\EppManifest.dll,-101" /f
  122.     Reg.exe add %%k /v "MUIVerb" /t REG_SZ /d "Windows 安全中心" /f
  123.     Reg.exe add %%k /v "Position" /t REG_SZ /d "Bottom" /f
  124.     Reg.exe add %%k /v "SeparatorAfter" /t REG_SZ /d "" /f
  125.     Reg.exe add %%k /v "SeparatorBefore" /t REG_SZ /d "" /f
  126.     Reg.exe add %%k /v "SubCommands" /t REG_SZ /d "" /f
  127. )
  128. Rem 二级菜单 安全中心主页
  129. for %%k in ("%_regkey2%" "%_regkey3%" "%_regkey4%") do (
  130.     Reg.exe add "%%k\shell\001flyout" /v "Icon" /t REG_SZ /d "%ProgramFiles%\Windows Defender\EppManifest.dll,-101" /f
  131.     Reg.exe add "%%k\shell\001flyout" /v "MUIVerb" /t REG_SZ /d "&安全中心主页" /f
  132.     Reg.exe add "%%k\shell\001flyout" /v "SeparatorAfter" /t REG_SZ /d "" /f
  133.     Reg.exe add "%%k\shell\001flyout" /v "SeparatorBefore" /t REG_SZ /d "" /f
  134.     Reg.exe add "%%k\shell\001flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  135.     Reg.exe add "%%k\shell\001flyout" /v "CommandFlags" /t REG_DWORD /d "64" /f
  136.     Reg.exe add "%%k\shell\001flyout\command" /ve /t REG_SZ /d "explorer windowsdefender:" /f
  137. )
  138. Rem 二级菜单 病毒和威胁防护
  139. for %%k in ("%_regkey2%" "%_regkey3%" "%_regkey4%") do (
  140.     Reg.exe add "%%k\shell\002flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  141.     Reg.exe add "%%k\shell\002flyout" /v "MUIVerb" /t REG_SZ /d "&病毒和威胁防护" /f
  142.     Reg.exe add "%%k\shell\002flyout" /v "Position" /t REG_SZ /d "Bottom" /f
  143.     Reg.exe add "%%k\shell\002flyout" /v "SubCommands" /t REG_SZ /d "" /f
  144.     Reg.exe add "%%k\shell\002flyout\shell" /v "SubCommands" /t REG_SZ /d "" /f
  145.     Reg.exe add "%%k\shell\002flyout\shell\001" /v "MUIVerb" /t REG_SZ /d "病毒和威胁防护 设置主页" /f
  146.     Reg.exe add "%%k\shell\002flyout\shell\001" /v "SeparatorAfter" /t REG_SZ /d "" /f
  147.     Reg.exe add "%%k\shell\002flyout\shell\001" /v "SeparatorBefore" /t REG_SZ /d "" /f
  148.     Reg.exe add "%%k\shell\002flyout\shell\001" /v "HasLUAShield" /t REG_SZ /d "" /f
  149.     Reg.exe add "%%k\shell\002flyout\shell\001" /v "CommandFlags" /t REG_DWORD /d "64" /f
  150.     Reg.exe add "%%k\shell\002flyout\shell\001\command" /ve /t REG_SZ /d "explorer windowsdefender://threat" /f
  151.     Reg.exe add "%%k\shell\002flyout\shell\002" /v "HasLUAShield" /t REG_SZ /d "" /f
  152.     Reg.exe add "%%k\shell\002flyout\shell\002" /v "MUIVerb" /t REG_SZ /d "启用 实时防护和防篡改" /f
  153.     Reg.exe add "%%k\shell\002flyout\shell\002\command" /ve /t REG_SZ /d "%_cmd_scripts_enable%" /f
  154.     Reg.exe add "%%k\shell\002flyout\shell\003" /v "HasLUAShield" /t REG_SZ /d "" /f
  155.     Reg.exe add "%%k\shell\002flyout\shell\003" /v "MUIVerb" /t REG_SZ /d "禁用 实时防护和防篡改" /f
  156.     Reg.exe add "%%k\shell\002flyout\shell\003\command" /ve /t REG_SZ /d "%_cmd_scripts_disabled%" /f
  157. )
  158. Rem 二级菜单 账户保护
  159. for %%k in ("%_regkey2%" "%_regkey3%" "%_regkey4%") do (
  160.     Reg.exe add "%%k\shell\003flyout" /v "MUIVerb" /t REG_SZ /d "&账户保护" /f
  161.     Reg.exe add "%%k\shell\003flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  162.     Reg.exe add "%%k\shell\003flyout\command" /ve /t REG_SZ /d "explorer windowsdefender://account" /f
  163. )
  164. Rem 二级菜单 防火墙和网络保护
  165. for %%k in ("%_regkey2%" "%_regkey3%" "%_regkey4%") do (
  166.     Reg.exe add "%%k\shell\004flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  167.     Reg.exe add "%%k\shell\004flyout" /v "MUIVerb" /t REG_SZ /d "&防火墙和网络保护" /f
  168.     Reg.exe add "%%k\shell\004flyout" /v "Position" /t REG_SZ /d "Bottom" /f
  169.     Reg.exe add "%%k\shell\004flyout" /v "SubCommands" /t REG_SZ /d "" /f
  170.     Reg.exe add "%%k\shell\004flyout\shell" /v "SubCommands" /t REG_SZ /d "" /f
  171.     Reg.exe add "%%k\shell\004flyout\shell\001" /v "MUIVerb" /t REG_SZ /d "防火墙和网络保护 设置主页" /f
  172.     Reg.exe add "%%k\shell\004flyout\shell\001" /v "SeparatorAfter" /t REG_SZ /d "" /f
  173.     Reg.exe add "%%k\shell\004flyout\shell\001" /v "SeparatorBefore" /t REG_SZ /d "" /f
  174.     Reg.exe add "%%k\shell\004flyout\shell\001" /v "HasLUAShield" /t REG_SZ /d "" /f
  175.     Reg.exe add "%%k\shell\004flyout\shell\001" /v "CommandFlags" /t REG_DWORD /d "64" /f
  176.     Reg.exe add "%%k\shell\004flyout\shell\001\command" /ve /t REG_SZ /d "explorer windowsdefender://network" /f
  177.     Reg.exe add "%%k\shell\004flyout\shell\002" /v "HasLUAShield" /t REG_SZ /d "" /f
  178.     Reg.exe add "%%k\shell\004flyout\shell\002" /v "MUIVerb" /t REG_SZ /d "启用 Windows 防火墙" /f
  179.     Reg.exe add "%%k\shell\004flyout\shell\002\command" /ve /t REG_SZ /d "powershell.exe -windowstyle hidden -command "Start-Process cmd -ArgumentList '/s,/c,netsh advfirewall set allprofiles state on' -Verb runAs"" /f
  180.     Reg.exe add "%%k\shell\004flyout\shell\003" /v "HasLUAShield" /t REG_SZ /d "" /f
  181.     Reg.exe add "%%k\shell\004flyout\shell\003" /v "MUIVerb" /t REG_SZ /d "禁用 Windows 防火墙" /f
  182.     Reg.exe add "%%k\shell\004flyout\shell\003\command" /ve /t REG_SZ /d "powershell.exe -windowstyle hidden -command "Start-Process cmd -ArgumentList '/s,/c,netsh advfirewall set allprofiles state off' -Verb runAs"" /f
  183. )
  184.   Rem 二级菜单 应用和浏览器控制
  185. for %%k in ("%_regkey2%" "%_regkey3%" "%_regkey4%") do (
  186.     Reg.exe add "%%k\shell\005flyout" /v "MUIVerb" /t REG_SZ /d "&应用和浏览器控制" /f
  187.     Reg.exe add "%%k\shell\005flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  188.     Reg.exe add "%%k\shell\005flyout\command" /ve /t REG_SZ /d "explorer windowsdefender://appbrowser" /f
  189. )
  190. Rem 二级菜单 设备安全性
  191. for %%k in ("%_regkey2%" "%_regkey3%" "%_regkey4%") do (
  192.     Reg.exe add "%%k\shell\006flyout" /v "MUIVerb" /t REG_SZ /d "&设备安全性" /f
  193.     Reg.exe add "%%k\shell\006flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  194.     Reg.exe add "%%k\shell\006flyout\command" /ve /t REG_SZ /d "explorer windowsdefender://devicesecurity" /f
  195. )
  196. Rem 二级菜单 设备性能和运行状况
  197. for %%k in ("%_regkey2%" "%_regkey3%" "%_regkey4%") do (
  198.     Reg.exe add "%%k\shell\007flyout" /v "MUIVerb" /t REG_SZ /d "&设备性能和运行状况" /f
  199.     Reg.exe add "%%k\shell\007flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  200.     Reg.exe add "%%k\shell\007flyout\command" /ve /t REG_SZ /d "explorer windowsdefender://perfhealth" /f
  201. )
  202. Rem 二级菜单 家庭选项
  203. for %%k in ("%_regkey2%" "%_regkey3%" "%_regkey4%") do (
  204.     Reg.exe add "%%k\shell\008flyout" /v "MUIVerb" /t REG_SZ /d "&家庭选项" /f
  205.     Reg.exe add "%%k\shell\008flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  206.     Reg.exe add "%%k\shell\008flyout\command" /ve /t REG_SZ /d "explorer windowsdefender://family" /f
  207. )
  208. Rem 二级菜单 保护历史记录
  209. for %%k in ("%_regkey2%" "%_regkey3%" "%_regkey4%") do (
  210.     Reg.exe add "%%k\shell\009flyout" /v "MUIVerb" /t REG_SZ /d "&保护历史记录" /f
  211.     Reg.exe add "%%k\shell\009flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  212.     Reg.exe add "%%k\shell\009flyout\command" /ve /t REG_SZ /d "explorer windowsdefender://history" /f
  213. )
  214. Rem 二级菜单 安全提供程序
  215. for %%k in ("%_regkey2%" "%_regkey3%" "%_regkey4%") do (
  216.     Reg.exe add "%%k\shell\010flyout" /v "MUIVerb" /t REG_SZ /d "&安全提供程序" /f
  217.     Reg.exe add "%%k\shell\010flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  218.     Reg.exe add "%%k\shell\010flyout\command" /ve /t REG_SZ /d "explorer windowsdefender://providers" /f
  219. )
  220. Rem 二级菜单 通知
  221. for %%k in ("%_regkey2%" "%_regkey3%" "%_regkey4%") do (
  222.     Reg.exe add "%%k\shell\011flyout" /v "MUIVerb" /t REG_SZ /d "&通知" /f
  223.     Reg.exe add "%%k\shell\011flyout" /v "HasLUAShield" /t REG_SZ /d "" /f
  224.     Reg.exe add "%%k\shell\011flyout\command" /ve /t REG_SZ /d "explorer windowsdefender://settings" /f
  225. )
  226. REM 添加排除WinDefCtl件夹限制访问及白名单
  227. powershell -ExecutionPolicy Bypass -NoProfile -Command "Add-MpPreference -ExclusionProcess '%~dp0WinDefCtl.exe'"
  228. powershell -ExecutionPolicy Bypass -NoProfile -Command "Add-MpPreference -ControlledFolderAccessAllowedApplications '%ComSpec%'"
  229. powershell -ExecutionPolicy Bypass -NoProfile -Command "Add-MpPreference -ControlledFolderAccessAllowedApplications 'C:\Windows\System32\cmd.exe'"
  230. powershell -ExecutionPolicy Bypass -NoProfile -Command "Add-MpPreference -ControlledFolderAccessAllowedApplications '%~dp0WinDefCtl.exe'"
  231. exit

  232. :uninstall
  233. REM 删除残留注册项
  234. reg delete "%_regkey1%" /f
  235. for %%i in ("%_regkey2%" "%_regkey3%" "%_regkey4%" "%_regkey5%") do reg delete %%i /f
  236. REM 移除排除WinDefCtl文件夹限制访问及白名单
  237. powershell -ExecutionPolicy Bypass -NoProfile -Command "Remove-MpPreference -ExclusionProcess '%~dp0WinDefCtl.exe'"
  238. powershell -ExecutionPolicy Bypass -NoProfile -Command "Remove-MpPreference -ControlledFolderAccessAllowedApplications '%ComSpec%'"
  239. powershell -ExecutionPolicy Bypass -NoProfile -Command "Remove-MpPreference -ControlledFolderAccessAllowedApplications 'C:\Windows\System32\cmd.exe'"
  240. powershell -ExecutionPolicy Bypass -NoProfile -Command "Remove-MpPreference -ControlledFolderAccessAllowedApplications '%~dp0WinDefCtl.exe'"
  241. exit

  242. :OUT
  243. exit
复制代码



使用方法WinDefCtl.ps1和 右键整合的批处理放同一目录 然后运行批处理 进行 右键功能添加和删除
网盘下载 自解压包也行https://cloud.189.cn/t/qUf6va6n6N3q(访问码:df2a)



2#
发表于 昨天 16:36 | 只看该作者
感谢您的分享!
回复

使用道具 举报

3#
发表于 昨天 16:44 | 只看该作者
感谢分享!
回复

使用道具 举报

4#
发表于 昨天 16:55 | 只看该作者
感谢分享!
回复

使用道具 举报

5#
发表于 昨天 17:00 | 只看该作者
感谢分享
回复

使用道具 举报

6#
发表于 昨天 17:09 | 只看该作者
谢谢大佬分享
回复

使用道具 举报

7#
发表于 昨天 17:16 | 只看该作者
感谢分享
回复

使用道具 举报

8#
发表于 昨天 17:27 | 只看该作者
感谢分享
回复

使用道具 举报

9#
发表于 昨天 17:50 | 只看该作者
这个强大
回复

使用道具 举报

10#
发表于 昨天 18:06 | 只看该作者
感谢分享
回复

使用道具 举报

11#
发表于 昨天 18:07 | 只看该作者
感谢分享!
回复

使用道具 举报

12#
发表于 昨天 18:08 | 只看该作者
感謝大大分享!^^ 辛苦了!
回复

使用道具 举报

13#
发表于 昨天 18:28 | 只看该作者
谢谢楼主分享
回复

使用道具 举报

14#
发表于 昨天 18:41 | 只看该作者
这个好,感谢分享
回复

使用道具 举报

15#
发表于 昨天 18:44 | 只看该作者
感谢分享,收下了
回复

使用道具 举报

16#
发表于 昨天 19:16 | 只看该作者
感谢分享!
回复

使用道具 举报

17#
发表于 昨天 19:27 | 只看该作者
感谢分享
回复

使用道具 举报

18#
发表于 昨天 20:06 | 只看该作者
可以直接分析文件吗?复制出来的好像有中文符号

点评

我上传不了压缩文件。。。。。  详情 回复 发表于 昨天 20:13
回复

使用道具 举报

19#
 楼主| 发表于 昨天 20:13 | 只看该作者
yuaijueyuan 发表于 2025-12-13 20:06
可以直接分析文件吗?复制出来的好像有中文符号

我上传不了压缩文件。。。。。
回复

使用道具 举报

20#
发表于 昨天 20:29 | 只看该作者
qq8899399 发表于 2025-12-13 20:13
我上传不了压缩文件。。。。。

上链接

点评

https://cloud.189.cn/t/qUf6va6n6N3q(访问码:df2a)  详情 回复 发表于 昨天 20:47
回复

使用道具 举报

21#
 楼主| 发表于 昨天 20:47 | 只看该作者

点评

好人  详情 回复 发表于 昨天 21:13
回复

使用道具 举报

22#
发表于 昨天 21:13 | 只看该作者
qq8899399 发表于 2025-12-13 20:47
https://cloud.189.cn/t/qUf6va6n6N3q(访问码:df2a)

好人
回复

使用道具 举报

23#
发表于 昨天 21:14 | 只看该作者
谢谢楼主分享,谢谢20楼朋友上传分享!
回复

使用道具 举报

24#
发表于 昨天 21:36 | 只看该作者
支持折腾~
回复

使用道具 举报

25#
发表于 昨天 21:54 | 只看该作者
感谢您的分享!
回复

使用道具 举报

26#
发表于 昨天 22:03 | 只看该作者
这个有点意思  谢谢分享
回复

使用道具 举报

27#
发表于 昨天 22:43 | 只看该作者
有能卸载 小娜的吗
回复

使用道具 举报

28#
发表于 昨天 22:49 | 只看该作者
感谢分享
回复

使用道具 举报

29#
发表于 1 小时前 | 只看该作者
原版系统很有用的。
回复

使用道具 举报

30#
发表于 1 小时前 | 只看该作者
纯路过~
回复

使用道具 举报

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

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2025-12-14 02:16

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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