Pregunta

Estos códigos permiten que tenga acceso al registro y apropiación de los valores lastvisitedMRU que están en un formato no legible. Lo que hice aquí fue para convertirlos en un formato legible. I los colocó en una matriz y salida de ellos, en la consola.

La salida es la siguiente:
C : \ P r o g r a m F i l e s \ i P o d \ f i l e . t x t

¿Cómo se quita los espacios en el medio?

Gracias de antemano.

try
        {
            RegistryKey rk = Registry.CurrentUser;

            rk = rk.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedMRU", false);
            PrintKeys(rk);
        }

        catch (Exception MyError)
        {
            Console.WriteLine("An error has occurred: " + MyError.Message);
        }
    }

    static void PrintKeys(RegistryKey rk)
    {
        if (rk == null)
        {
            Console.WriteLine("No specified registry key!");
            return;
        }

        String[] names = rk.GetValueNames();

        Console.WriteLine("Subkeys of " + rk.Name);
        Console.WriteLine("-----------------------------------------------");

        foreach (String s in names)
        {
            try
            {
                if (s == "MRUList")
                {
                    continue;
                }

                else
                {
                    try
                    {
                        Byte[] byteValue = (Byte[])rk.GetValue(s);

                        string str = BitConverter.ToString(byteValue).Replace("00", "");

                        str = BitConverter.ToString(byteValue).Replace("-", "");
        //str binry AND VAR CONVERTED TEXT

                        Console.WriteLine(s + " Contains the value of : " + str);

                        StringBuilder sb = new StringBuilder();

                        for (int i = 0; i <= str.Length - 2; i += 2)
                        {
                            sb.Append(Convert.ToString(Convert.ToChar(Int32.Parse(str.Substring(i, 2), System.Globalization.NumberStyles.HexNumber))));
                        }

                        String val = Convert.ToString(sb).Replace(" ", "");

                        Console.WriteLine(s + " Contains the value of : " + val);
                    }

                    catch (Exception Errors)
                    {
                        Console.WriteLine("An error has occurred: " + Errors.Message);
                    }
                }

                //rk.Close();
            }

            catch (Exception MyError)
            {
                Console.WriteLine("An error has occurred: " + MyError.Message);
            }

            Console.WriteLine("-----------------------------------------------");
            //rk.Close();
        }
¿Fue útil?

Solución

El binario hay codificada Unicode. Me fijo su código y verifiqué que está trabajando en mi XP. Sin embargo, no funciona en Windows 7 o Vista porque LastVisitedMRU ya no existe.

    static void Main(string[] args)
    {
        try
        {
            RegistryKey rk = Registry.CurrentUser;
            rk = rk.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedMRU", false);
            PrintKeys(rk);
        }

        catch (Exception ex)
        {
            Console.WriteLine("An error has occurred: " + ex.Message);
        }
    }

    static void PrintKeys(RegistryKey rk)
    {
        if (rk == null)
        {
            Console.WriteLine("No specified registry key!");
            return;
        }

        foreach (String s in rk.GetValueNames())
        {
            if (s == "MRUList")
            {
                continue;
            }
            Byte[] byteValue = (Byte[])rk.GetValue(s);

            UnicodeEncoding unicode = new UnicodeEncoding();
            string val = unicode.GetString(byteValue);

            Console.Out.WriteLine(val);
        }
        Console.ReadLine();
    }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top