powershell - 禁止Outlook弹出窗口允许访问

标签 powershell outlook

运行以下PowerShell代码时:

$Outlook = New-Object -ComObject Outlook.Application   
$Stores = $Outlook.Session.Stores 
$Accounts = $Outlook.Session.Accounts
$Accounts | Select-Object DisplayName, UserName, SmtpAddress, ExchangeMailboxServerName, ExchangeMailboxServerVersion

弹出安全警告:

enter image description here

根据Microsoft的解决方法。例如,一个人可以Create a COM Add-in for Outlook而不是使用here解释的Outlook COM Object。自定义COM Add-in for Outlook的另一个示例张贴在StackOverflow上的here上,但用于另一种语言。

使用Globals.ThisAddIn.Application应该使这个possible,不是吗?有人可以向我解释如何使用PowerShell吗?如果我们能避免此弹出窗口,那将是很好,因为它只会使用户感到困惑。

最佳答案

通过在运行代码之前以本地管理员身份编辑注册表来找到workaround:

Function Remove-OutlookSecurityPromptHC {
    [CmdLetBinding()]
    Param()

    if (Test-Path -Path 'HKLM:\SOFTWARE\Microsoft\Office\14.0\Outlook') {
        Write-Verbose 'Found MS Outlook 2010'

        if (-not (Test-Path -Path 'HKLM:\SOFTWARE\Microsoft\Office\14.0\Outlook\Security')) {
            New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Office\14.0\Outlook\Security' | Out-Null
        }
        Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Office\14.0\Outlook\Security' -Name ObjectModelGuard -Value 2
        Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Office\14.0\Outlook\Security' -Name PromptOOMSend -Value 2
        Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Office\14.0\Outlook\Security' -Name AdminSecurityMode -Value 3
        Write-Verbose 'Outlook warning suppressed'
    }

    if (Test-Path -Path 'HKLM:\SOFTWARE\Microsoft\Office\12.0\Outlook') {
        Write-Verbose 'Found MS Outlook 2007'

        if (-not (Test-Path -Path 'HKLM:\SOFTWARE\Microsoft\Office\12.0\Outlook\Security')) {
            New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Office\12.0\Outlook\Security' | Out-Null
        }
        Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Office\12.0\Outlook\Security' -Name ObjectModelGuard -Value 2
        Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Office\12.0\Outlook\Security' -Name PromptOOMSend -Value 2
        Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Office\12.0\Outlook\Security' -Name AdminSecurityMode -Value 3
        Write-Verbose 'Outlook warning suppressed'
    }
}

Remove-OutlookSecurityPromptHC -Verbose

运行此代码后,可能需要重新启动/注销才能生效。

关于powershell - 禁止Outlook弹出窗口允许访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36302096/

相关文章:

PowerShell:无法将数据写入包含方括号的 UNC 路径

performance - PowerShell 服务器在修改大 .xml 文件时崩溃

iis - 使用Powershell为IIS虚拟目录设置 “Allow clients to upload files”

delphi - 使用 Delphi 发送 Outlook 电子邮件

c# - 在 C# 中使用 LinkLabel 超链接电子邮件地址

powershell - 为什么 select-object -first 1 不返回数组以保持一致性?

powershell - Powershell远程查询Server 2003的事件日志

php - 如何使用 php rest 范围在 outlook 日历上编写事件?

emacs - 在Outlook中使用Emacs时的字符编码转换错误

excel - 如何从Excel中获取收件人电子邮件地址?