问题
When running the following PowerShell code:
$Outlook = New-Object -ComObject Outlook.Application
$Stores = $Outlook.Session.Stores
$Accounts = $Outlook.Session.Accounts
$Accounts | Select-Object DisplayName, UserName, SmtpAddress, ExchangeMailboxServerName, ExchangeMailboxServerVersion
A security warning pops-up:
According to Microsoft there are ways around this. For instance, one can Create a COM Add-in for Outlook
instead of using the Outlook COM Object
as explained here. Another example of a custom COM Add-in for Outlook
is posted here on StackOverflow but for another language.
Using Globals.ThisAddIn.Application
should make this possible, No? Can someone explain to me how this is done with PowerShell? It would be great if we could avoid this pop-up as it will only confuse users.
回答1:
Found a workaround by editing the registry as local administrator before running the code:
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
After running this code a reboot/logoff might be needed before it becomes active.
回答2:
You either need to make sure an up-to-date anti-virus product is installed on the machine (if you can control the client environment) or use Redemption or Clickyes to work around the security prompts. See http://www.outlookcode.com/article.aspx?id=52 for more details.
来源:https://stackoverflow.com/questions/36302096/suppress-outlook-pop-up-allow-access