Пример #1
0
        public static string GetValueHKCU(string path, string name, string defaultValue)
        {
            string      res = "";
            RegistryKey rk  = Registry.CurrentUser.CreateSubKey(path);

            try
            {
                if (rk.GetValue(name) == null)
                {
                    SetValueHKCU(path, name, defaultValue);
                    res = defaultValue;
                }
                else
                {
                    res = rk.GetValue(name).ToString();
                }
            }
            catch (Exception err)
            {
                CEventLog.Write(string.Format("CRegistry.GetValueHKCU({0},{1},{2}) -> {3}", path, name, defaultValue, err.GetAllMessages()));
            }
            finally
            {
                rk.Close();
            }
            return(res);
        }
Пример #2
0
        public static void SetValueHKCU(string path, string name, string value)
        {
            RegistryKey rk = Registry.CurrentUser.CreateSubKey(path);

            try
            {
                rk.SetValue(name, value);
            }
            catch (Exception err)
            {
                CEventLog.Write(string.Format("CRegistry.SetValue({0},{1},{2}) -> {3}", path, name, value, err.Message));
            }
            finally
            {
                rk.Close();
            }
        }
Пример #3
0
 public static void CreatePath(String inPath)
 {
     try
     {
         string[] splPath = (inPath.TrimEnd('\\') + "\\").Split('\\');
         String   dirs    = splPath[0] + "\\" + splPath[1];
         for (int i = 2; i < splPath.Length; i++)
         {
             if (!System.IO.Directory.Exists(dirs))
             {
                 System.IO.Directory.CreateDirectory(dirs);
             }
             dirs += "\\" + splPath[i];
         }
     }
     catch (Exception err)
     {
         CEventLog.Write(string.Format("CFile.CreatePath({0}) -> {1}", inPath, err.GetAllMessages()));
     }
 }
Пример #4
0
        public static string GetValueHKLM(string path, string name)
        {
            string      res = "";
            RegistryKey rk  = Registry.LocalMachine.CreateSubKey(path, RegistryKeyPermissionCheck.ReadSubTree);

            try
            {
                string value = rk.GetValue(name).ToString();
                res = value;
            }
            catch (Exception err)
            {
                CEventLog.Write(string.Format("CRegistry.GetValueHKLM({0},{1}) -> {2}", path, name, err.GetAllMessages()));
            }
            finally
            {
                rk.Close();
            }
            return(res);
        }