using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Win32;
using System.Data;
///<summary>
///安裝軟體明細
///</summary>
public partial class Demo_SetupAppList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblDate.Text = DateTime.Now.ToLongDateString();
lblComputerName.Text = Environment.GetEnvironmentVariable("COMPUTERNAME");
DataTable AppTable = new DataTable();
AppTable.TableName = "AppTable";
string[] ColumnList = { "Name", "Version", "Path" };
foreach (string s in ColumnList)
{
DataColumn InsertCol = new DataColumn(s);
InsertCol.ColumnName = s;
AppTable.Columns.Add(InsertCol);
}
string AppName = string.Empty, AppVersion = string.Empty, AppPath = string.Empty;
using (RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall", false))
{
if (key != null)
{
foreach (string keyName in key.GetSubKeyNames())
{
using (RegistryKey key2 = key.OpenSubKey(keyName, false))
{
if (key2 != null)
{
string SoftwareName = key2.GetValue("DisplayName", "").ToString();
string SoftwareVersion = key2.GetValue("DisplayVersion", "").ToString();
string InstallLocation = key2.GetValue("InstallLocation", "").ToString();
/*判斷程式名稱與安裝路徑不等於空白*/
if (!string.IsNullOrEmpty(SoftwareName) & !string.IsNullOrEmpty(InstallLocation))
{
//AppList += (string.Format("{0} \t {1} \t {2} \r\n", SoftwareName, SoftwareVersion, InstallLocation));
AppName += (string.Format("{0} <br>", SoftwareName));
AppVersion += (string.Format("{0} <br>", SoftwareVersion));
AppPath += (string.Format("{0} <br>", InstallLocation));
DataRow InsertRow = AppTable.NewRow();
InsertRow["Name"] = SoftwareName;
InsertRow["Version"] = SoftwareVersion;
InsertRow["Path"] = InstallLocation;
AppTable.Rows.Add(InsertRow);
}
}
}
}
}
}
gvw1.DataSource = AppTable;
gvw1.DataBind();
}
}