首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在excel VBA中使用Powershell启用Windows Defender

在excel VBA中使用Powershell启用Windows Defender
EN

Stack Overflow用户
提问于 2019-09-01 06:08:50
回答 1查看 442关注 0票数 0

在下面的代码中,我尝试使用powershell启用Windows Defender

代码语言:javascript
复制
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任何想法..?

我试过了,但对我也不起作用

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2019-09-01 21:59:09

你可以试试这些:

禁用Windows Defender

代码语言:javascript
复制
$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

代码语言:javascript
复制
$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的观点,你应该为此发布一个新的问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57741905

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档