0

这些代码允许我访问注册表并获取不可读格式的 lastvisitedMRU 值。我在这里所做的是将它们转换为可读的格式。我将它们放在一个数组中并将它们输出到控制台。

输出如下:
C : \ P r o g r a m F i l e s \ i P o d \ f i l e . t x t

如何删除中间的间距?

提前致谢。

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();
        }
4

1 回答 1

0

那里的二进制文件是 unicode 编码的。我修复了您的代码并验证它在我的 XP 上运行。但是,它不适用于 Windows 7 或 Vista,因为 LastVisitedMRU 不再存在。

    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();
    }
于 2010-12-13T05:31:40.067 回答