From 163dc17b493c129d9b311c8dbadd2aafc318bde4 Mon Sep 17 00:00:00 2001 From: duffyduck Date: Fri, 3 Apr 2026 19:22:53 +0200 Subject: [PATCH] Add option to suppress Outlook security prompt New setting "Outlook-Sicherheitsabfrage automatisch erlauben" sets registry keys under HKCU\Policies\Microsoft\Office\16.0\ Outlook\Security to auto-approve Object Model Guard prompts. Applied at app startup and when saving settings. Disabling the option removes the registry values (back to Outlook default). Works with all Outlook versions (2016-2024, same registry path). No admin rights needed (HKCU). Outlook must be restarted after changing this setting. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../Models/UserSettings.cs | 41 +++++++++++++++++++ src/StarfaceOutlookSync/UI/MainForm.cs | 4 +- src/StarfaceOutlookSync/UI/SettingsForm.cs | 18 +++++--- 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/StarfaceOutlookSync/Models/UserSettings.cs b/src/StarfaceOutlookSync/Models/UserSettings.cs index ce22524d..c88118e0 100644 --- a/src/StarfaceOutlookSync/Models/UserSettings.cs +++ b/src/StarfaceOutlookSync/Models/UserSettings.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using Microsoft.Win32; using Newtonsoft.Json; namespace StarfaceOutlookSync.Models @@ -8,6 +9,7 @@ namespace StarfaceOutlookSync.Models { public bool StartMinimized { get; set; } = false; public bool SyncOnStart { get; set; } = false; + public bool AutoAcceptOutlookPrompt { get; set; } = false; private static readonly string SettingsFile = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @@ -33,6 +35,45 @@ namespace StarfaceOutlookSync.Models File.WriteAllText(SettingsFile, JsonConvert.SerializeObject(this, Formatting.Indented)); } catch { } + + ApplyOutlookSecuritySetting(); + } + + public void ApplyOutlookSecuritySetting() + { + try + { + var regPath = @"Software\Policies\Microsoft\Office\16.0\Outlook\Security"; + + if (AutoAcceptOutlookPrompt) + { + // Alle Outlook Object Model Guard Prompts unterdruecken + 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("AdminSecurityMode", 3, RegistryValueKind.DWord); + key.Close(); + } + else + { + // Zurueck auf Standard (Werte loeschen) + try + { + var key = Registry.CurrentUser.OpenSubKey(regPath, true); + if (key != null) + { + try { key.DeleteValue("ObjectModelGuard"); } catch { } + try { key.DeleteValue("PromptOOMAddressBookAccess"); } catch { } + try { key.DeleteValue("PromptOOMAddressInformationAccess"); } catch { } + try { key.DeleteValue("AdminSecurityMode"); } catch { } + key.Close(); + } + } + catch { } + } + } + catch { } } } } diff --git a/src/StarfaceOutlookSync/UI/MainForm.cs b/src/StarfaceOutlookSync/UI/MainForm.cs index 774fede1..3d0cc5cc 100644 --- a/src/StarfaceOutlookSync/UI/MainForm.cs +++ b/src/StarfaceOutlookSync/UI/MainForm.cs @@ -31,8 +31,10 @@ namespace StarfaceOutlookSync.UI SetupAutoSync(); RefreshProfileList(); - // Minimiert starten falls in Einstellungen aktiviert + // Einstellungen laden und anwenden var settings = UserSettings.Load(); + settings.ApplyOutlookSecuritySetting(); + if (settings.StartMinimized) { WindowState = FormWindowState.Minimized; diff --git a/src/StarfaceOutlookSync/UI/SettingsForm.cs b/src/StarfaceOutlookSync/UI/SettingsForm.cs index 592e37e3..92354aec 100644 --- a/src/StarfaceOutlookSync/UI/SettingsForm.cs +++ b/src/StarfaceOutlookSync/UI/SettingsForm.cs @@ -6,7 +6,7 @@ namespace StarfaceOutlookSync.UI { public class SettingsForm : Form { - private CheckBox _chkStartMinimized, _chkSyncOnStart; + private CheckBox _chkStartMinimized, _chkSyncOnStart, _chkAutoAcceptOutlook; private Button _btnSave, _btnCancel; private readonly UserSettings _settings; @@ -19,7 +19,7 @@ namespace StarfaceOutlookSync.UI private void InitializeComponent() { Text = "Einstellungen"; - Size = new Size(350, 210); + Size = new Size(380, 250); FormBorderStyle = FormBorderStyle.FixedDialog; MaximizeBox = false; MinimizeBox = false; @@ -40,20 +40,27 @@ namespace StarfaceOutlookSync.UI Checked = _settings.SyncOnStart }; + _chkAutoAcceptOutlook = new CheckBox + { + Text = "Outlook-Sicherheitsabfrage automatisch erlauben", + Left = 20, Top = 80, AutoSize = true, + Checked = _settings.AutoAcceptOutlookPrompt + }; + _btnSave = new Button { - Text = "Speichern", Left = 80, Top = 130, Width = 85, Height = 28, + Text = "Speichern", Left = 95, Top = 160, Width = 85, Height = 28, DialogResult = DialogResult.None }; _btnSave.Click += (s, e) => Save(); _btnCancel = new Button { - Text = "Abbrechen", Left = 174, Top = 130, Width = 85, Height = 28, + Text = "Abbrechen", Left = 189, Top = 160, Width = 85, Height = 28, DialogResult = DialogResult.Cancel }; - Controls.AddRange(new Control[] { _chkStartMinimized, _chkSyncOnStart, _btnSave, _btnCancel }); + Controls.AddRange(new Control[] { _chkStartMinimized, _chkSyncOnStart, _chkAutoAcceptOutlook, _btnSave, _btnCancel }); AcceptButton = _btnSave; CancelButton = _btnCancel; } @@ -62,6 +69,7 @@ namespace StarfaceOutlookSync.UI { _settings.StartMinimized = _chkStartMinimized.Checked; _settings.SyncOnStart = _chkSyncOnStart.Checked; + _settings.AutoAcceptOutlookPrompt = _chkAutoAcceptOutlook.Checked; _settings.Save(); DialogResult = DialogResult.OK; Close();