Browse Source

Merge branch 'master' of http://y:1000/Fork

yuzhengyang 8 years ago
parent
commit
1603521edc

+ 63 - 0
Fork.Net/Y.Utils.Net20/ComputerUtils/RegisterTool.cs

@@ -0,0 +1,63 @@
+using Microsoft.Win32;
+using System;
+
+namespace Y.Utils.Net20.ComputerUtils
+{
+    public class RegisterTool
+    {
+        /// <summary>
+        /// 写入注册表项
+        /// </summary>
+        /// <param name="key">SOFTWARE\\NC_VideoConferenceSystem</param>
+        /// <param name="name">RegTime</param>
+        /// <param name="value">yyyy-MM-dd hh:mm:ss</param>
+        public static bool Write(string key, string name, string value)
+        {
+            try
+            {
+                RegistryKey RKey = Registry.LocalMachine.OpenSubKey(key, true);
+                if (RKey == null)
+                    RKey = Registry.LocalMachine.CreateSubKey(key);
+                RKey.SetValue(name, value);
+                return true;
+            }
+            catch (Exception e)
+            {
+                return false;
+            }
+        }
+        /// <summary>
+        /// 读取注册表项
+        /// </summary>
+        /// <param name="key">SOFTWARE\\NC_VideoConferenceSystem</param>
+        /// <param name="name">Path</param>
+        /// <returns></returns>
+        public static string Read(string key, string name)
+        {
+            try
+            {
+                RegistryKey RKey = Registry.LocalMachine.OpenSubKey(key, true);
+                if (RKey != null)
+                {
+                    return RKey.GetValue(name) != null ? RKey.GetValue(name).ToString() : "";
+                }
+            }
+            catch (Exception e) { }
+            return null;
+        }
+        public static bool Delete(string key, string name)
+        {
+            try
+            {
+                RegistryKey RKey = Registry.LocalMachine.OpenSubKey(key, true);
+                if (RKey != null)
+                    RKey.DeleteValue(name);
+                return true;
+            }
+            catch (Exception e)
+            {
+                return false;
+            }
+        }
+    }
+}

+ 1 - 0
Fork.Net/Y.Utils.Net20/Y.Utils.Net20.csproj

@@ -44,6 +44,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="AppUtils\AppUnique.cs" />
+    <Compile Include="ComputerUtils\RegisterTool.cs" />
     <Compile Include="EncryptUtils\AesTool.cs" />
     <Compile Include="EncryptUtils\DesTool.cs" />
     <Compile Include="EnumUtils\FlagsEnumTool.cs" />