我正在为两个注册表项提取 url 和 url 时间。并希望在列表视图中显示它。使用 to 循环我如何通过循环填充 listview 第一列,然后再填充第二列,因为 url 和 time 都在不同的 reg 键中.....
listViewCookies.Columns.Add("TYPED URL", 300);
listViewCookies.Columns.Add("TIME", 400);
string[] url = new string[2];
ListViewItem item;
using (RegistryKey rk = Registry.Users.OpenSubKey(strSID + @"\Software\Microsoft\Internet Explorer\TypedURLs"))
{
try
{
foreach (string u in rk.GetValueNames())
{
url[0] = rk.GetValue(u).ToString();
}
}
catch { }
}
using (RegistryKey rk = Registry.Users.OpenSubKey(strSID + @"\Software\Microsoft\Internet Explorer\TypedURLsTime"))
{
try
{
foreach (string u in rk.GetValueNames())
{
object val = rk.GetValue(u);
DateTime output = DateTime.MinValue;
if (val is byte[] && ((byte[])val).Length == 8)
{
byte[] bytes = (byte[])val;
System.Runtime.InteropServices.ComTypes.FILETIME ft = new System.Runtime.InteropServices.ComTypes.FILETIME();
int valLow = bytes[0] + 256 * (bytes[1] + 256 * (bytes[2] + 256 * bytes[3]));
int valTwo = bytes[4] + 256 * (bytes[5] + 256 * (bytes[6] + 256 * bytes[7]));
ft.dwLowDateTime = valLow;
ft.dwHighDateTime = valTwo;
DateTime UTC = DateTime.FromFileTimeUtc((((long)ft.dwHighDateTime) << 32) + ft.dwLowDateTime);
TimeZoneInfo lcl = TimeZoneInfo.Local;
TimeZoneInfo utc = TimeZoneInfo.Utc;
output = TimeZoneInfo.ConvertTime(UTC, utc, lcl);
url[1] = output.ToString();
}
}
}
catch { }
}
item = new ListViewItem(url);
listViewCookies.Items.Add(item);