忘记我啥时候AI试过一次,后面没继续折腾了#RequireAdmin
Local $sPathToExclude = "D:\TUPortable\TUPortable.exe"
Local $sLogFile = @ScriptDir & "\DefenderError.log"
; Validate path
If Not FileExists($sPathToExclude) Then
FileWrite($sLogFile, "错误: 路径不存在 - " & $sPathToExclude & @CRLF)
MsgBox(16, "错误", "路径不存在: " & $sPathToExclude)
Exit
EndIf
; Check Defender status
Local $sDefenderCheck = 'powershell -ExecutionPolicy Bypass -Command "Get-Service -Name WinDefend | Select-Object -ExpandProperty Status"'
Local $iDefenderStatus = RunWait(@ComSpec & " /c " & $sDefenderCheck & " > " & $sLogFile, "", @SW_HIDE)
Local $sStatus = FileRead($sLogFile)
If StringInStr($sStatus, "Running") = 0 Then
FileWrite($sLogFile, "错误: Windows Defender 服务未运行" & @CRLF)
MsgBox(16, "错误", "Windows Defender 服务未运行,可能被禁用或被其他杀毒软件接管")
Exit
EndIf
; Add to exclusion list
Local $sPowerShellCmd = 'powershell -ExecutionPolicy Bypass -Command "Add-MpPreference -ExclusionPath ''' & $sPathToExclude & '''"'
Local $iReturn = RunWait(@ComSpec & " /c " & $sPowerShellCmd & " >> " & $sLogFile, "", @SW_HIDE)
; Check result
If $iReturn = 0 Then
MsgBox(64, "成功", "已将 " & $sPathToExclude & " 添加到 Windows Defender 白名单!")
Else
FileWrite($sLogFile, "错误代码: " & $iReturn & @CRLF & "命令: " & $sPowerShellCmd & @CRLF)
MsgBox(16, "错误", "添加白名单失败,错误代码: " & $iReturn & @CRLF & "详情见: " & $sLogFile)
EndIf
|