alielie
2026-06-15 f08871fe7d148d667f2f11f80f64de71a0d9504c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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;
            }
        }
    }
}