Un metodo molto semplice per recuperare la lista dei programmi installati sul proprio pc, compresi anche gli aggiornamenti effettuati tramite Microsoft Windows Update:
VB.NET:
1: Imports Microsoft.Win32
2: Dim dtListPrograms As DataTable = New DataTable()
3: dtListPrograms.Columns.Add(New DataColumn("Name", GetType(String)))
4: Dim row As DataRow
5:
6: Dim reg As RegistryKey = Registry.LocalMachine
7: reg = reg.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
8: For Each keyName As String In reg.GetSubKeyNames()
9: row = dtListPrograms.NewRow()
10: If (reg.OpenSubKey(keyName).GetValue("DisplayName") Is Nothing) Then
11: row(0) = keyName
12: Else
13: row(0) = reg.OpenSubKey(keyName).GetValue("DisplayName").ToString()
14: End If
15: dtListPrograms.Rows.Add(row)
16: Next
C#:
1: using Microsoft.Win32;
2: ...
3: DataTable dtListPrograms = new DataTable();
4: dtListPrograms.Columns.Add( new DataColumn( "Name", typeof( string)));
5: DataRow row;
6: RegistryKey reg = Registry.LocalMachine;
7: reg = reg.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");
8: foreach( string keyName in reg.GetSubKeyNames())
9: {
10: row = dtListPrograms.NewRow();
11: if( reg.OpenSubKey(keyName).GetValue("DisplayName") == null)
12: row[0] = keyName;
13: else
14: row[0] = reg.OpenSubKey(keyName).GetValue("DisplayName").ToString();
15: dtListPrograms.Rows.Add(row);
16: }
Il tutto si basa nell'elencare le sottochiavi di:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall
(Test: sistema Windows XP, utente administrator)
0 commenti:
Post a Comment