Files
OfficeTool/Services/OfficeDetector.cs
hariel1985 4937ac4b1c Initial release v1.01 — InstaSoft Office Tool
Office deployment wizard for InstaSoft customers:
- Install Office 2019/2021/2024 (Standard, Professional Plus, Home & Business)
- Auto-download ODT from Microsoft, generate config XML, run setup
- Remove existing Office installations (C2R + MSI)
- License troubleshooting via ospp.vbs (dstatus, unpkey)
- Fluent Design UI (WPF .NET Framework 4.8, Win7+ compatible)
- Hungarian interface, multi-language Office installation
- Product key input with auto-activation support

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 05:40:50 +02:00

105 sor
3.8 KiB
C#

using System.Collections.Generic;
using InstaSoftOfficeTool.Models;
using Microsoft.Win32;
namespace InstaSoftOfficeTool.Services
{
public static class OfficeDetector
{
public static List<InstalledOffice> Detect()
{
var results = new List<InstalledOffice>();
// Check Click-to-Run
DetectClickToRun(results);
// Check MSI-based installs
DetectMsi(results);
return results;
}
private static void DetectClickToRun(List<InstalledOffice> results)
{
try
{
using (var key = Registry.LocalMachine.OpenSubKey(
@"SOFTWARE\Microsoft\Office\ClickToRun\Configuration"))
{
if (key == null) return;
var productIds = key.GetValue("ProductReleaseIds") as string;
var versionToReport = key.GetValue("VersionToReport") as string;
if (!string.IsNullOrEmpty(productIds))
{
results.Add(new InstalledOffice
{
DisplayName = "Microsoft Office Click-to-Run (" + productIds + ")",
Version = versionToReport ?? "",
IsClickToRun = true,
IsSelected = true
});
}
}
}
catch { }
}
private static void DetectMsi(List<InstalledOffice> results)
{
var uninstallPaths = new[]
{
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
};
foreach (var path in uninstallPaths)
{
try
{
using (var key = Registry.LocalMachine.OpenSubKey(path))
{
if (key == null) continue;
foreach (var subKeyName in key.GetSubKeyNames())
{
using (var subKey = key.OpenSubKey(subKeyName))
{
if (subKey == null) continue;
var displayName = subKey.GetValue("DisplayName") as string;
var publisher = subKey.GetValue("Publisher") as string;
if (displayName != null &&
publisher != null &&
publisher.Contains("Microsoft") &&
(displayName.Contains("Microsoft Office") ||
displayName.Contains("Microsoft 365")))
{
var version = subKey.GetValue("DisplayVersion") as string ?? "";
// Skip Click-to-Run updater entries
if (displayName.Contains("Click-to-Run") &&
!displayName.Contains("Microsoft Office"))
continue;
results.Add(new InstalledOffice
{
DisplayName = displayName,
Version = version,
ProductCode = subKeyName,
IsClickToRun = false,
IsSelected = true
});
}
}
}
}
}
catch { }
}
}
}
}