diff --git a/src/StarfaceOutlookSync/Services/OutlookContactsService.cs b/src/StarfaceOutlookSync/Services/OutlookContactsService.cs index 2ddab49f..db34ecc9 100644 --- a/src/StarfaceOutlookSync/Services/OutlookContactsService.cs +++ b/src/StarfaceOutlookSync/Services/OutlookContactsService.cs @@ -26,20 +26,35 @@ namespace StarfaceOutlookSync.Services { if (_outlookApp != null) return _outlookApp; + // Versuch 1: Laufende Outlook-Instanz finden try { - // Versuche laufende Outlook-Instanz zu finden _outlookApp = (Outlook.Application)GetActiveComObject("Outlook.Application"); _weStartedOutlook = false; + return _outlookApp; } - catch - { - // Outlook starten falls nicht laufend - _outlookApp = new Outlook.Application(); - _weStartedOutlook = true; - } + catch { } - return _outlookApp; + // Versuch 2: Outlook per COM starten + try + { + var outlookType = Type.GetTypeFromProgID("Outlook.Application"); + if (outlookType != null) + { + _outlookApp = (Outlook.Application)Activator.CreateInstance(outlookType); + _weStartedOutlook = true; + return _outlookApp; + } + } + catch { } + + throw new InvalidOperationException( + "Outlook Classic konnte nicht gefunden werden.\n\n" + + "Moegliche Ursachen:\n" + + "- Outlook Classic ist nicht installiert\n" + + "- Outlook Classic ist nicht gestartet\n" + + "- Das neue Outlook wird verwendet (wird noch nicht unterstuetzt)\n\n" + + "Bitte Outlook Classic starten und erneut versuchen."); } public List GetContactFolderPaths()