引入空間名稱:Microsoft.win32
添加listbox。
代碼:
private void Form1_Load(object sender, EventArgs e)
{
foreach (string name in GetRegistName())
{
listBox1.Items.Add( name + ":" + GetRegistData(name) );
}
}
private string GetRegistData(string name)//程序安裝位置
{
string registData;
RegistryKey hkml = Registry.LocalMachine;
RegistryKey aimdir = hkml.OpenSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun", true);
registData = aimdir.GetValue(name).ToString();
return registData;
}
private string[] GetRegistName()//名稱
{
RegistryKey hkml = Registry.LocalMachine;
RegistryKey aimdir = hkml.OpenSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun", true);
return aimdir.GetValueNames();
}