using Microsoft.Win32; using System; namespace HMI.Simple.Util { public class RegUtil { private static string Company = "JingCe"; private static string Program = "HMI"; public static string GetLocaltion() { string registryPath = $@"SOFTWARE\{Company}\{Program}"; // 尝试打开注册表键 using (RegistryKey key = Registry.CurrentUser.OpenSubKey(registryPath)) { if (key == null) { throw new Exception("注册表不存在,请先运行一次HMI"); } string value = key.GetValue("Location")?.ToString(); if (string.IsNullOrEmpty(value)) { throw new Exception("注册表不存在,请先运行一次HMI"); } return value; } } } }