C#检验注册表中的某一注册表项的值

using System;
using System.Windows.Forms;
using Microsoft.Win32;

private static string GetVersionInfo()
        {
            string result = null;
            RegistryKey key;
            try
            {
                key = Registry.LocalMachine.OpenSubKey(Define.ProductVersionPath);
                if(key != null)
                {
                    object o = key.GetValue(Define.VersionSign);
                    return o.ToString();
                }
            }
            catch(Exception e)
            {
                Helper.Write(e.ToString());
            }
            return result;
        }

其中:Registry静态类提供表示 Windows 注册表中的根项的 Microsoft.Win32.RegistryKey 对象,并提供访问项/值对的 static 方法。

RegistryKey类表示 Windows 注册表中的项级节点。此类sealed,不可继承。

object GetValue(string name):检索与指定名称关联的值。如果注册表中不存在名称/值对,则返回 null。

RegistryKey OpenSubKey(string name):以只读方式检索子项。