运行以下PowerShell代码时:
$Outlook = New-Object -ComObject Outlook.Application
$Stores = $Outlook.Session.Stores
$Accounts = $Outlook.Session.Accounts
$Accounts | Select-Object DisplayName, UserName, SmtpAddress, ExchangeMailboxServerName, ExchangeMailboxServerVersion
弹出安全警告:
根据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/