在下面的代码中,我尝试使用powershell启用Windows Defender
Sub Enable_Disable_Windows_Defender_Using_PowerShell()
Dim wshShell As Object
Dim wshShellExec As Object
Dim strCommand As String
Rem Enable = false - Disable = true
strCommand = "Powershell -nologo -WindowStyle Hidden -ExecutionPolicy Bypass -Command ""Set-MpPreference -DisableRealtimeMonitoring $false"""
Set wshShell = CreateObject("WScript.Shell")
Set wshShellExec = wshShell.Exec(strCommand)
End Sub在执行代码时没有错误,但我没有得到Windows Defender Eabled任何想法..?
我试过了,但对我也不起作用
Sub Enable_Disable_Windows_Defender_Using_PowerShell()
Dim wshShell As Object
Dim wshShellExec As Object
Dim strCommand As String
Rem Enable = false - Disable = true
strCommand = "Powershell -nologo -Command ""Start-Process powershell -Verb runAs"""
Set wshShell = CreateObject("WScript.Shell")
Set wshShellExec = wshShell.Exec(strCommand)
strCommand = "Powershell -nologo -WindowStyle Hidden -ExecutionPolicy Bypass -Command ""Set-MpPreference -DisableRealtimeMonitoring $false"""
Set wshShell = CreateObject("WScript.Shell")
Set wshShellExec = wshShell.Exec(strCommand)
End Sub发布于 2019-09-01 21:59:09
你可以试试这些:
禁用Windows Defender
$regpath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows Defender"
if (!(Test-Path $regpath -PathType Container)) {
New-Item -Path $regpath -ItemType Container -Force
}
Set-ItemProperty -Path $regpath -Name "DisableAntiSpyware" -Value 1 -Type DWord -Force
# stop the service and set it to Disabled
Stop-Service -Name WinDefend -Confirm:$false -Force
Set-Service -Name WinDefend -StartupType Disabled启用Windows Defender
$regpath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows Defender"
if (Test-Path $regpath -PathType Container) {
Set-ItemProperty -Path $regpath -Name "DisableAntiSpyware" -Value 0 -Type DWord -Force
# or remove the whole registry key "Windows Defender"
# Remove-Item -Path $regpath -Force
}
# set the service to startup Automatic and start the service
Set-Service -Name WinDefend -StartupType Automatic
Start-Service -Name WinDefend -Confirm:$false你需要以管理员身份运行它,至于如何做到这一点,我同意Lee_Daily的观点,你应该为此发布一个新的问题。
https://stackoverflow.com/questions/57741905
复制相似问题