Example #1
0
        private static RegistryValue ReadRegistryValue(XmlReader reader)
        {
            string name = string.Empty;

            Microsoft.Win32.RegistryValueKind type = Microsoft.Win32.RegistryValueKind.String;
            string value = string.Empty;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.Name)
                {
                case ValueNameAttributeName:
                    name = reader.ReadContentAsString();
                    break;

                case ValueTypeAttributeName:
                    type = reader.ReadContentAsEnum <Microsoft.Win32.RegistryValueKind>();
                    break;

                case ValueValueAttributeName:
                    value = reader.ReadContentAsString();
                    break;
                }
            }
            reader.MoveToElement();
            return(new RegistryValue(name, type, value));
        }
Example #2
0
 internal static extern IntPtr RegQueryValueExW(
     IntPtr hKey,
     string lpValueName,
     int lpReserved,
     ref Microsoft.Win32.RegistryValueKind type,
     IntPtr lpData,
     ref int lpcbData);
Example #3
0
        public void SaveSettings(string Title, string Value, Microsoft.Win32.RegistryValueKind kind)
        {
            Microsoft.Win32.RegistryKey regKey =
                Microsoft.Win32.Registry.CurrentUser.CreateSubKey(strAppPath);

            regKey.SetValue(Title, Value, kind);
        }
 public static extern int RegSetValueEx(
     IntPtr hKey,
     [MarshalAs(UnmanagedType.LPStr)] string lpValueName,
     int Reserved, //Should be zero
     Microsoft.Win32.RegistryValueKind dwType,
     byte[] lpData,
     int cbData);
Example #5
0
        public static object GetDefaultData(this Microsoft.Win32.RegistryValueKind valueKind)
        {
            switch (valueKind)
            {
            case Microsoft.Win32.RegistryValueKind.Binary:
                return(new byte[0]);

            case Microsoft.Win32.RegistryValueKind.DWord:
                return(0);

            case Microsoft.Win32.RegistryValueKind.ExpandString:
                return(string.Empty);

            case Microsoft.Win32.RegistryValueKind.MultiString:
                return(new string[0]);

            case Microsoft.Win32.RegistryValueKind.QWord:
                return((long)0);

            case Microsoft.Win32.RegistryValueKind.String:
                return(string.Empty);

            case Microsoft.Win32.RegistryValueKind.Unknown:
            default:
                return(null);
            } // End switch (valueKind)
        }     // End Function GetDefaultData
Example #6
0
        }     // End Function GetDefaultData

        public static string ToDataType(this Microsoft.Win32.RegistryValueKind valueKind)
        {
            switch (valueKind)
            {
            case Microsoft.Win32.RegistryValueKind.Binary:
                return("REG_BINARY");

            case Microsoft.Win32.RegistryValueKind.DWord:
                return("REG_DWORD");

            case Microsoft.Win32.RegistryValueKind.ExpandString:
                return("REG_EXPAND_SZ");

            case Microsoft.Win32.RegistryValueKind.MultiString:
                return("REG_MULTI_SZ");

            case Microsoft.Win32.RegistryValueKind.QWord:
                return("REG_QWORD");

            case Microsoft.Win32.RegistryValueKind.String:
                return("REG_SZ");

            case Microsoft.Win32.RegistryValueKind.Unknown:
                return("REG_UNKNOWN");

            default:
                return(string.Empty);
            } // End switch (valueKind)
        }     // End Function ToDataType
Example #7
0
 public static extern int CM_Get_DevNode_Registry_Property(
     uint deviceInstance,
     uint property,
     out Microsoft.Win32.RegistryValueKind pulRegDataType,
     IntPtr buffer,
     ref uint length,
     uint flags);
Example #8
0
        } // End Function RecursivelyListKeys

        public static string ToDataType(Microsoft.Win32.RegistryValueKind valueKind)
        {
            switch (valueKind)
            {
            case Microsoft.Win32.RegistryValueKind.Binary:
                return("REG_BINARY");    // Binärwert

            case Microsoft.Win32.RegistryValueKind.DWord:
                return("REG_DWORD");    // DWord (32-Bit)

            case Microsoft.Win32.RegistryValueKind.ExpandString:
                return("REG_EXPAND_SZ");    // Wert der erweiterbaren Zeichenfolge

            case Microsoft.Win32.RegistryValueKind.MultiString:
                return("REG_MULTI_SZ");    // Wert der mehrteiligen Zeichenfolge

            case Microsoft.Win32.RegistryValueKind.QWord:
                return("REG_QWORD");    // QWord (64-Bit)

            case Microsoft.Win32.RegistryValueKind.String:
                return("REG_SZ");    // Zeichenfolge

            case Microsoft.Win32.RegistryValueKind.Unknown:
                return("REG_UNKNOWN");

            default:
                return(string.Empty);
            } // End switch (valueKind)
        }     // End Functon ToDataType
Example #9
0
        public static string ToString(Microsoft.Win32.RegistryValueKind valueKind, object valueData)
        {
            string data;

            switch (valueKind)
            {
            case Microsoft.Win32.RegistryValueKind.Binary:
                data = System.Text.Encoding.ASCII.GetString((byte[])valueData);
                break;

            case Microsoft.Win32.RegistryValueKind.MultiString:
                data = string.Join(" ", (string[])valueData);
                break;

            case Microsoft.Win32.RegistryValueKind.DWord:
                data = ((uint)((int)valueData)).ToString();
                break;

            case Microsoft.Win32.RegistryValueKind.QWord:
                data = ((ulong)((long)valueData)).ToString();
                break;

            case Microsoft.Win32.RegistryValueKind.String:
            case Microsoft.Win32.RegistryValueKind.ExpandString:
                data = valueData.ToString();
                break;

            case Microsoft.Win32.RegistryValueKind.Unknown:
            default:
                data = string.Empty;
                break;
            }
            return(data);
        }
Example #10
0
 public override void WriteValue(string name, Microsoft.Win32.RegistryValueKind kind, object data)
 {
     xmlWriter.WriteStartElement("value");
     xmlWriter.WriteAttributeString("name", name);
     xmlWriter.WriteAttributeString("type", RegistryExplorer.Registry.Extensions.ToDataType(kind));
     xmlWriter.WriteAttributeString("data", RegistryExplorer.Registry.RegValue.ToString(kind, data));
     xmlWriter.WriteEndElement();
 }
Example #11
0
 public override void WriteValue(string name, Microsoft.Win32.RegistryValueKind kind, object data)
 {
     Writer.WriteLine("Value {0}", counter++);
     Writer.WriteLine("    Name:\t{0}", name);
     Writer.WriteLine("    Type:\t{0}", RegistryExplorer.Registry.Extensions.ToDataType(kind));
     Writer.WriteLine("    Data:\t{0}", RegistryExplorer.Registry.RegValue.ToString(kind, data));
     Writer.WriteLine();
 }
Example #12
0
        private static void TestRegistryGetRegistryValueKind()
        {
            string regKey   = ConsoleTest.GetNextInput("Registry Key: ", "HKEY_CURRENT_USER\\Software\\SqlMirror");
            string regValue = ConsoleTest.GetNextInput("Registry Value: ", "Status");

            Microsoft.Win32.RegistryValueKind registryValueKind = RegistryHelper.GetRegistryValueKind(Logger, regKey, regValue);
            Console.WriteLine(string.Format("RegistryValueKind: {0}", registryValueKind.ToString()));

            ConsoleTest.GetNextInput("Press Enter to end test");
        }
Example #13
0
 private void StartNewRegValueTask(Microsoft.Win32.RegistryValueKind valueKind, string valueName, string valueSerialized)
 {
     SubmitTaskAsync(WriteRegistryElementTaskId, ManagementObject,
                     new Dictionary <string, string>
     {
         { "KeyPath", $"{cbRegRootKey.SelectedItem}\\{tbRegPath.Text}" },
         { "Action", ((int)WriteRegistryElementAction.SetValue).ToString() },
         { "OldName", valueName },
         { "NewValue", valueSerialized },
         { "ValueType", RegistryValueKindToREG(valueKind) }
     }, new OnTaskStatusChangeDelegate(OnWriteRegistryElementTaskChange));
 }
Example #14
0
 private string GetValueTypeIcon(Microsoft.Win32.RegistryValueKind registryValueKind)
 {
     if (registryValueKind == Microsoft.Win32.RegistryValueKind.ExpandString ||
         registryValueKind == Microsoft.Win32.RegistryValueKind.MultiString ||
         registryValueKind == Microsoft.Win32.RegistryValueKind.String)
     {
         return("ascii");
     }
     else
     {
         return("binary");
     }
 }
Example #15
0
        //public static bool PCL_rotationPCD(string inputpcdfile, string outputpcdfile, float x1, float y1, float z1, float x2, float y2, float z2, float angle)
        //{
        //    try
        //    {
        //        return PCLApi.pcdRotationArbitraryAxisapi(inputpcdfile, outputpcdfile, x1, y1, z1, x2, y2, z2, angle);
        //    }
        //    catch(Exception err)
        //    {
        //        Trace.TraceError(err.ToString());
        //        return false;
        //    }
        //}

        //public static bool PCL_calibrateMatrixFileConvert(string sourceCommaSplitFile, string destSpaceSplitFile)
        //{
        //    try
        //    {
        //        if (File.Exists(destSpaceSplitFile))
        //        {
        //            DateTime now = DateTime.Now;
        //            File.Copy(destSpaceSplitFile, string.Format("{0}.{1}.{2:D2}.{3:D2}.{4:D2}.{5:D2}.{6:D2}.backup",
        //                destSpaceSplitFile, now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second), true);
        //        }

        //        using (StreamReader sr = new StreamReader(sourceCommaSplitFile))
        //        using (StreamWriter sw = new StreamWriter(destSpaceSplitFile, false))
        //        {
        //            string matrix_comma = sr.ReadToEnd();
        //            string matrix_space = matrix_comma.Replace(',', ' ');
        //            sw.Write(matrix_space);
        //        }

        //        return true;
        //    }
        //    catch(Exception err)
        //    {
        //        Trace.TraceError(err.ToString());
        //        return false;
        //    }
        //}

        //public static string PCL_pcd2image(string pcdfile, int meanK, int kernel, int planar_threshold, int minx, int maxx, int miny, int maxy, int minz, int maxz, int min_cloud_size = 100)
        //{
        //    try
        //    {
        //        StringBuilder result_str = new StringBuilder(1000);
        //        int len = PCLApi.pcd2imageapi(pcdfile, result_str,
        //            meanK: meanK, kernel_size: kernel, planar_threshold: planar_threshold,
        //            minx: minx, maxx: maxx, miny: miny, maxy: maxy, minz: minz, maxz: maxz,
        //            min_cloud_size: min_cloud_size);
        //        if (len < 0) return null;
        //        string image_name = result_str.ToString().Substring(0, len).Trim();
        //        return image_name;
        //    }
        //    catch(Exception err)
        //    {
        //        Trace.TraceError(err.ToString());
        //        return null;
        //    }
        //}

        //public static int PCL_Preprocess()
        //{

        //    return 0;
        //}

        //public static bool PCL_calcTransform(Point3D p1, Point3D p2, Point3D p3, Point3D pw1, Point3D pw2, Point3D pw3, out double Trx, out double Try, out double Trz)
        //{
        //    try
        //    {
        //        StringBuilder result_str = new StringBuilder(1000);
        //        int len = PCLApi.calcTransformapi(
        //            new double[3] { p1.X, p1.Y, p1.Z }, new double[3] { p2.X, p2.Y, p2.Z }, new double[3] { p3.X, p3.Y, p3.Z },
        //            new double[3] { pw1.X, pw1.Y, pw1.Z }, new double[3] { pw2.X, pw2.Y, pw2.Z }, new double[3] { pw3.X, pw3.Y, pw3.Z },
        //            result_str);
        //        string matrix_str = result_str.ToString().Substring(0, len).Trim();
        //        Translation translation = new Translation(matrix_str.Split());
        //        Trx = translation.Trx; Try = translation.Try; Trz = translation.Trz;
        //        return true;
        //    }
        //    catch (Exception err)
        //    {
        //        Trx = 0; Try = 0; Trz = 0;
        //        Trace.TraceError(err.ToString());
        //        return false;
        //    }
        //}

        //public static bool PCL_downsampling(string inputfile, string outputfile)
        //{
        //    string output_dowsample = inputfile.Replace(".pcd", "_downsample.pcd");
        //    string output_outlierremoval = inputfile.Replace(".pcd", "_outlierremoval.pcd");

        //    int resCount = PCLApi.downsamplingapi(inputfile, output_dowsample, output_outlierremoval, outputfile, radius: 50, std_dev_mul: (float)2.0);
        //    return resCount > 2000; //
        //}


        //public static bool PCL_downsamplingxyz(string inputfile, string outputfile, float minx, float maxx, float miny, float maxy, float minz, float maxz)
        //{
        //    string output_dowsample = inputfile.Replace(".pcd", "_downsample.pcd");
        //    string output_outlierremoval = inputfile.Replace(".pcd", "_outlierremoval.pcd");

        //    int resCount = PCLApi.downsamplingxyzapi(inputfile, output_dowsample, output_outlierremoval, outputfile, minx, maxx, miny, maxy, minz, maxz, radius: 50, std_dev_mul: (float)2.0, min_cloud_size: 7000);
        //    return resCount > 2000; //
        //}

        //public static bool PCL_downsamplingxyz_sor_voxel(string inputfile, string outputfile, float minx, float maxx, float miny, float maxy, float minz, float maxz)
        //{
        //    string output_dowsample = inputfile.Replace(".pcd", "_downsample.pcd");
        //    string output_outlierremoval = inputfile.Replace(".pcd", "_outlierremoval.pcd");

        //    int resCount = PCLApi.downsamplingxyz_sor_voxelapi(inputfile, output_dowsample, output_outlierremoval, outputfile, minx, maxx, miny, maxy, minz, maxz, meanK: 20, radius: 50, std_dev_mul: (float)1.2, min_cloud_size: 7000);
        //    return resCount > 2000; //
        //}

        ///// <summary>
        ///// 点云三角化重建,待完善
        ///// </summary>
        ///// <param name="inputfile"></param>
        ///// <param name="outputfile"></param>
        //public static void PCL_surfaceReconstruct(string inputfile, string outputfile)
        //{
        //    PCLApi.greedyTriangulationapi(inputfile, outputfile, search_radius: 50, mu: 15);
        //}

        //public static void Meshlab_Viewer(string filename)
        //{
        //    if(!File.Exists(Properties.Settings.Default.meshlab_install_path))
        //    {
        //        System.Windows.Forms.MessageBox.Show("文件:\"" + Properties.Settings.Default.meshlab_install_path + "\"不存在");
        //        return;
        //    }

        //    string absolutePath = System.IO.Path.Combine(FileIO.BaseDirectory, filename);
        //    if (File.Exists(absolutePath))
        //        filename = absolutePath;

        //    ProcessStartInfo startInfo = new ProcessStartInfo(Properties.Settings.Default.meshlab_install_path);
        //    startInfo.UseShellExecute = false;
        //    startInfo.CreateNoWindow = true;

        //    startInfo.Arguments = filename;
        //    Process p = Process.Start(startInfo);
        //}
        public static void Meshlab_Viewer(string filename)
        {
            string strMeshLabPath = "";

            try
            {
                string softName   = "meshlab";
                string strKeyName = string.Empty;
                string softPath   = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\";
                Microsoft.Win32.RegistryKey regKey    = Microsoft.Win32.Registry.LocalMachine;
                Microsoft.Win32.RegistryKey regSubKey = regKey.OpenSubKey(softPath + softName + ".exe", false);

                object objResult = regSubKey.GetValue(strKeyName);
                Microsoft.Win32.RegistryValueKind regValueKind = regSubKey.GetValueKind(strKeyName);
                if (regValueKind == Microsoft.Win32.RegistryValueKind.String)
                {
                    strMeshLabPath = objResult.ToString();
                }
            }
            catch
            {
                System.Windows.MessageBox.Show("请确认安装了MeshLab"); return;
            }


            if (strMeshLabPath == "" && !File.Exists(strMeshLabPath))
            {
                System.Windows.MessageBox.Show("文件:\"" + strMeshLabPath + "\"不存在");
                return;
            }

            //string absolutePath = System.IO.Path.Combine(FileIO.BaseDirectory, filename);
            string absolutePath = filename;

            if (File.Exists(absolutePath))
            {
                filename = absolutePath;
            }

            ProcessStartInfo startInfo = new ProcessStartInfo(strMeshLabPath);

            startInfo.UseShellExecute = false;
            startInfo.CreateNoWindow  = true;

            startInfo.Arguments = filename;
            Process p = Process.Start(startInfo);

            p.WaitForExit();
        }
Example #16
0
 /// <summary>
 /// 寫入指定註冊表
 /// </summary>
 /// <param name="name">要儲存之值的名稱</param>
 /// <param name="value">要儲存之值的名稱</param>
 /// <param name="valueKind">儲存資料時要使用的登錄資料型別</param>
 /// <returns></returns>
 public Boolean RegistrykeyWrite(string name, object value, Microsoft.Win32.RegistryValueKind valueKind)
 {
     try
     {
         Microsoft.Win32.RegistryKey regkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(Registrykey);
         regkey.SetValue(name, value, valueKind);
         regkey.Close();
     }
     catch (Exception ex)
     {
         RegistryException = ex.Message;
         return(false);
     }
     return(true);
 }
Example #17
0
        private string RegistryValueKindToREG(Microsoft.Win32.RegistryValueKind valueKind)
        {
            switch (valueKind)
            {
            case Microsoft.Win32.RegistryValueKind.DWord: return("REG_DWORD");

            case Microsoft.Win32.RegistryValueKind.QWord: return("REG_QWORD");

            case Microsoft.Win32.RegistryValueKind.String: return("REG_SZ");

            case Microsoft.Win32.RegistryValueKind.ExpandString: return("REG_EXPAND_SZ");

            case Microsoft.Win32.RegistryValueKind.Binary: return("REG_BINARY");

            case Microsoft.Win32.RegistryValueKind.MultiString: return("REG_MULTI_SZ");
            }
            return("REG_UNKNOWN");
        }
Example #18
0
        private void OnNewValueAction(Microsoft.Win32.RegistryValueKind valueKind)
        {
            if (tvwKeys.SelectedNode == null)
            {
                return;
            }

            Microsoft.Win32.RegistryKey key = (Microsoft.Win32.RegistryKey)tvwKeys.SelectedNode.Tag;
            string name = RegistryExplorer.Registry.RegUtility.GetNewValueName(key);

            ListViewItem item = AddValueToList(key,
                                               new RegistryExplorer.Registry.RegValue(name, valueKind,
                                                                                      RegistryExplorer.Registry.Extensions.GetDefaultData(valueKind)
                                                                                      )
                                               );

            lstValues.LabelEdit = true;
            item.BeginEdit();
        }
        /// <summary>
        /// set the value in reg
        /// </summary>
        /// <param name="folder">Reg Folder</param>
        /// <param name="Name">value name</param>
        /// <param name="Value">The value</param>
        /// <param name="ValueKind">Kind of the value.</param>
        protected void RegSetValue(eWURegKeys folder, string Name, object Value, Microsoft.Win32.RegistryValueKind ValueKind)
        {
            if (!_AllowWrite)
            {
                throw new Exception("Write is not allowed in this mode!");
            }
            string key = "";

            switch (folder)
            {
            case eWURegKeys.HKLM_WU:
                key = HKLM_WU; break;

            case eWURegKeys.HKLM_WUAU:
                key = HKLM_WUAU; break;

            default: throw new NotSupportedException();
            }
            Microsoft.Win32.Registry.SetValue(key, Name, Value);
        }
Example #20
0
        /// <summary>
        /// 查找注册表获取注册表项的字符串值,返回值确定是否能找到此项的值。
        /// </summary>
        /// <param name="name">要打开的子项的名称或路径</param>
        /// <param name="strKeyName">要检索的值的名称</param>
        /// <param name="value">注册表值</param>
        /// <returns></returns>
        private static bool GetRegValue(string name, string strKeyName, ref string value)
        {
            bool isSuccess = false;

            Microsoft.Win32.RegistryKey regSubKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(name, false);

            object objResult = regSubKey?.GetValue(strKeyName);

            if (objResult != null)
            {
                Microsoft.Win32.RegistryValueKind regValueKind = regSubKey.GetValueKind(strKeyName);
                if (regValueKind == Microsoft.Win32.RegistryValueKind.String)
                {
                    value     = objResult.ToString();
                    isSuccess = true;
                }
            }
            regSubKey?.Close();

            return(isSuccess);
        }
Example #21
0
        public static void ReadValue <TType>(ref TType result, Microsoft.Win32.RegistryKey key, string keyName,
                                             Microsoft.Win32.RegistryValueKind valueKind = Microsoft.Win32.RegistryValueKind.String)
        {
            try
            {
                object obj = key.GetValue(keyName);
                if (obj != null)
                {
                    result = (TType)Convert.ChangeType(obj, typeof(TType));
                    return;
                }
            }
            catch (Exception)
            {}

            try
            {
                key.SetValue(keyName, result, valueKind);
            }
            catch (Exception)
            {}
        }
Example #22
0
        public override void WriteValue(string name, Microsoft.Win32.RegistryValueKind kind, object data)
        {
            string dataString;

            switch (kind)
            {
            case Microsoft.Win32.RegistryValueKind.Binary:
                dataString = string.Format("hex:{0}", GetHexString((byte[])data));
                break;

            case Microsoft.Win32.RegistryValueKind.DWord:
                dataString = string.Format("dword:{0:x8}", (uint)((int)data));
                break;

            case Microsoft.Win32.RegistryValueKind.QWord:
                dataString = string.Format("qword:{0:x16}", (ulong)((long)data));
                break;

            case Microsoft.Win32.RegistryValueKind.ExpandString:
                dataString = string.Format("hex(2):{0}", GetHexString((string)data));
                break;

            case Microsoft.Win32.RegistryValueKind.MultiString:
                dataString = string.Format("hex(7):{0}", GetHexString((string[])data));
                break;

            case Microsoft.Win32.RegistryValueKind.String:
                dataString = string.Format("\"{0}\"", (string)data);
                break;

            case Microsoft.Win32.RegistryValueKind.Unknown:
            default:
                dataString = string.Empty;
                break;
            }
            Writer.WriteLine("\"{0}\"={1}", name, dataString);
        }
Example #23
0
        public CommandLineWidth(int width)
        {
            // http://technet.microsoft.com/en-us/library/cc781831.aspx
            // The value of this entry is an 4-byte hexadecimal value.
            // The first 2 bytes (high word) represent the number of lines that appear on the screen.
            // The last 2 bytes (low word) represent the number of lines of columns on the screen.
            Assert.IsTrue(width <= WidthMask, "width must be less than {0}", WidthMask);

            this.consoleKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(ConsoleKeyName, Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree);
            Assert.IsNotNull(consoleKey, "need ReadWriteSubTree for {0}", ConsoleKeyName);

            // ScreenBuffer
            this.originalScreenBufferValue = this.consoleKey.GetValue(ScreenBufferSizeValueName);
            if (null != this.originalScreenBufferValue)
            {
                this.originalScreenBufferKind = this.consoleKey.GetValueKind(ScreenBufferSizeValueName);
            }

            // WindowSize
            this.originalWindowSizeValue = this.consoleKey.GetValue(WindowSizeValueName);
            if (null != this.originalWindowSizeValue)
            {
                this.originalWindowSizeKind = this.consoleKey.GetValueKind(WindowSizeValueName);
            }
            this.originalQueried = true;

            int newWidth;

            // set ScreenBuffer
            newWidth = (((int)this.originalScreenBufferValue) & HeightMask) | (width & WidthMask);
            consoleKey.SetValue(ScreenBufferSizeValueName, newWidth);

            // set WindowSize
            newWidth = (((int)this.originalWindowSizeValue) & HeightMask) | (width & WidthMask);
            consoleKey.SetValue(WindowSizeValueName, newWidth);
        }
Example #24
0
 /// <summary>
 /// Sets all properties of the registry value.
 /// </summary>
 /// <param name="valueName">Name of the registry value</param>
 /// <param name="valueKind">Type of the registry value</param>
 /// <param name="valueData">Data of the registry value</param>
 public void setRegValue(string valueName, Microsoft.Win32.RegistryValueKind valueKind, object valueData)
 {
     this.valueName = valueName;
     this.valueKind = valueKind;
     this.valueData = valueData;
 }
 public static void SetValue(string keyName, string valueName, object value, Microsoft.Win32.RegistryValueKind valueKind)
 {
 }
 public void SetValue(string name, object value, Microsoft.Win32.RegistryValueKind valueKind)
 {
 }
Example #27
0
        public static System.Collections.Generic.Dictionary <string, string> RecursivelyListKeys(
            string registyBase,
            Microsoft.Win32.RegistryKey baseKey)
        {
            System.Collections.Generic.Dictionary <string, string> ls =
                new System.Collections.Generic.Dictionary <string, string>();



            string[] valueNames = baseKey.GetValueNames();
            System.Array.Sort(valueNames, delegate(string s1, string s2)
            {
                return(s1.CompareTo(s2));
            });


            foreach (string valueName in valueNames)
            {
                string key = baseKey.Name + @"\" + valueName;
                key = key.Substring(registyBase.Length + 1);
                key = key.Replace('\\', ':');

                try
                {
                    Microsoft.Win32.RegistryValueKind rvk = baseKey.GetValueKind(valueName);
                    string type  = ToDataType(rvk);
                    object value = baseKey.GetValue(valueName);

                    // https://docs.microsoft.com/en-us/windows/desktop/sysinfo/registry-value-types
                    if (rvk == Microsoft.Win32.RegistryValueKind.String)
                    {
                        string stringValue = System.Convert.ToString(value);
                        ls[key] = stringValue;
                    }
                    else if (rvk == Microsoft.Win32.RegistryValueKind.DWord)
                    {
                        int dwordValue = System.Convert.ToInt32(value);
                        ls[key] = dwordValue.ToString(System.Globalization.CultureInfo.InvariantCulture);
                    }
                    else if (rvk == Microsoft.Win32.RegistryValueKind.QWord)
                    {
                        long qwordValue = System.Convert.ToInt64(value);
                        ls[key] = qwordValue.ToString(System.Globalization.CultureInfo.InvariantCulture);
                    }
                    else if (rvk == Microsoft.Win32.RegistryValueKind.Binary)
                    {
                        byte[] binaryValue = (byte[])value;
                        ls[key] = System.Convert.ToBase64String(binaryValue);
                    }
                    else if (rvk == Microsoft.Win32.RegistryValueKind.MultiString)
                    {
                        string[] multiStringValue = (string[])value;
                        ls[key] = Newtonsoft.Json.JsonConvert.SerializeObject(multiStringValue);
                    }
                    else if (rvk == Microsoft.Win32.RegistryValueKind.ExpandString)
                    {
                        string expString = System.Convert.ToString(value);
                        ls[key] = expString;
                    }
                    else if (rvk == Microsoft.Win32.RegistryValueKind.None)
                    {
                        ls[key] = null;
                    }
                    else  // if (rvk == Microsoft.Win32.RegistryValueKind.Unknown)
                    {
                        ls[key] = System.Convert.ToString(value);
                    }
                }
                catch (System.Exception ex)
                {
                    ls[key] = ex.Message;
                }
            } // Next valueName


            string[] subkeys = baseKey.GetSubKeyNames();
            // System.Console.WriteLine(subkeys.Length);

            foreach (string subKey in subkeys)
            {
                string newBasePath = baseKey.Name + @"\" + subKey;
                newBasePath = newBasePath.Substring(registyBase.Length + 1);
                newBasePath = newBasePath.Replace('\\', ':');

                try
                {
                    Microsoft.Win32.RegistryKey sk = baseKey.OpenSubKey(subKey);
                    // ls.Add(newBasePath);

                    System.Collections.Generic.Dictionary <string, string> lss = RecursivelyListKeys(registyBase, sk);
                    // ls.AddRange(lss);

                    foreach (System.Collections.Generic.KeyValuePair <string, string> kvp in lss)
                    {
                        ls[kvp.Key] = kvp.Value;
                    }

                    lss.Clear();
                    lss = null;
                }
                catch (System.Exception ex)
                {
                    // ls.Add(newBasePath);
                    ls[newBasePath] = ex.Message;
                }
            } // Next subKey

            return(ls);
        } // End Function RecursivelyListKeys
Example #28
0
 /// <summary>
 /// Creates a registry value in ram.
 /// </summary>
 /// <param name="valueName">Name of the registry value</param>
 /// <param name="valueData">Data of the registry value</param>
 /// <param name="valueKind">Kind of the registry value</param>
 /// <returns>RegistryValue key object</returns>
 public RegistryValue value_create(string valueName, object valueData = null, Microsoft.Win32.RegistryValueKind valueKind = 0)
 {
     return(new RegistryValue(valueName, valueKind, valueData));
 }
Example #29
0
 /// <summary>
 /// Manuel initialization.
 /// </summary>
 /// <param name="valueName">Name of the registry value</param>
 /// <param name="valueKind">Type of the registry value</param>
 /// <param name="valueData">Data of the registry value</param>
 public RegistryValue(string valueName, Microsoft.Win32.RegistryValueKind valueKind, object valueData)
 {
     setRegValue(valueName, valueKind, valueData);
 }
Example #30
0
 abstract public void WriteValue(string name, Microsoft.Win32.RegistryValueKind kind, object data);