当前位置: 代码迷 >> WinCE >> WinCE的C#程序读写字符类型的注册表,使用Win32库的步骤。直接复制代码使用
  详细解决方案

WinCE的C#程序读写字符类型的注册表,使用Win32库的步骤。直接复制代码使用

热度:123   发布时间:2016-04-28 12:02:42.0
WinCE的C#程序读写字符类型的注册表,使用Win32库的方法。直接复制代码使用
        /// <summary>
        /// 获取注册表的字符类型
        /// </summary>
        /// <param name="strPath">注册表路径</param>
        /// <param name="strKey">注册表键</param>
        /// <param name="strValue">键值</param>
        /// <returns></returns>
        static public string RegReadString(string strPath,string strKey)
        {
            RegistryKey key = null;


            string strValue = "";
            try
            {
                key = Registry.LocalMachine.OpenSubKey(strPath, false);
                strValue = key.GetValue(strKey).ToString();
            }
            catch
            {
                key.Close();
                return strValue;
            }


            key.Close();
            return strValue;


        }


        /// <summary>
        /// 向注册表写入字符键值
        /// </summary>
        /// <param name="strPath">注册表路径</param>
        /// <param name="strKey">注册表键</param>
        /// <param name="strValue">键值</param>
        /// <returns></returns>
        static public bool RegWriteString(string strPath, string strKey,string strValue)
        {
            RegistryKey key = null;


            try
            {
                key = Registry.LocalMachine.OpenSubKey(strPath, true);
                key.SetValue(strKey, strValue);
            }
            catch
            {
                key.Close();
                return false;
            }


            key.Close();
            return true;




        }
  相关解决方案