Write Outlook security keys to both Policies and normal user path

On Terminal Servers, normal users cannot write to HKCU\Software\
Policies. Now also writes to HKCU\Software\Microsoft\Office\...\
Security which is always writable and also read by Outlook.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
duffyduck 2026-04-03 19:37:26 +02:00
parent 4484f19d14
commit c08a625348
1 changed files with 37 additions and 23 deletions

View File

@ -42,40 +42,54 @@ namespace StarfaceOutlookSync.Models
public void ApplyOutlookSecuritySetting()
{
// Alle Office-Versionen abdecken (16.0 = 2016/2019/2021/2024/365, 15.0 = 2013)
// Beide Pfade versuchen: Policies (GPO-Pfad) und direkt (normaler User-Pfad)
var versions = new[] { "16.0", "15.0" };
var prefixes = new[]
{
@"Software\Policies\Microsoft\Office", // GPO-Pfad (braucht ggf. Rechte)
@"Software\Microsoft\Office" // Normaler User-Pfad (immer schreibbar)
};
var securityValues = new (string name, int value)[]
{
("ObjectModelGuard", 2),
("PromptOOMAddressBookAccess", 2),
("PromptOOMAddressInformationAccess", 2),
("PromptOOMSend", 2),
("PromptOOMSaveAs", 2),
("PromptOOMFormulaAccess", 2),
("PromptOOMCustomAction", 2),
("PromptSimpleMAPISend", 2),
("PromptSimpleMAPINameResolve", 2),
("PromptSimpleMAPIOpenMessage", 2),
("AdminSecurityMode", 3),
};
foreach (var ver in versions)
{
try
foreach (var prefix in prefixes)
{
var regPath = $@"Software\Policies\Microsoft\Office\{ver}\Outlook\Security";
var regPath = $@"{prefix}\{ver}\Outlook\Security";
if (AutoAcceptOutlookPrompt)
try
{
var key = Registry.CurrentUser.CreateSubKey(regPath);
key.SetValue("ObjectModelGuard", 2, RegistryValueKind.DWord);
key.SetValue("PromptOOMAddressBookAccess", 2, RegistryValueKind.DWord);
key.SetValue("PromptOOMAddressInformationAccess", 2, RegistryValueKind.DWord);
key.SetValue("PromptOOMSend", 2, RegistryValueKind.DWord);
key.SetValue("PromptOOMSaveAs", 2, RegistryValueKind.DWord);
key.SetValue("PromptOOMFormulaAccess", 2, RegistryValueKind.DWord);
key.SetValue("PromptOOMCustomAction", 2, RegistryValueKind.DWord);
key.SetValue("PromptSimpleMAPISend", 2, RegistryValueKind.DWord);
key.SetValue("PromptSimpleMAPINameResolve", 2, RegistryValueKind.DWord);
key.SetValue("PromptSimpleMAPIOpenMessage", 2, RegistryValueKind.DWord);
key.SetValue("AdminSecurityMode", 3, RegistryValueKind.DWord);
key.Close();
}
else
{
try
if (AutoAcceptOutlookPrompt)
{
Registry.CurrentUser.DeleteSubKey(regPath, false);
var key = Registry.CurrentUser.CreateSubKey(regPath);
if (key != null)
{
foreach (var (name, value) in securityValues)
key.SetValue(name, value, RegistryValueKind.DWord);
key.Close();
}
}
else
{
try { Registry.CurrentUser.DeleteSubKey(regPath, false); } catch { }
}
catch { }
}
catch { }
}
catch { }
}
}
}