我安装程序的部分代码:
private void CheckStatusForm_Load(object sender, System.EventArgs e)
{
ListViewItem itemOs = lvSystemInfo.Items.Add("操作系统");
itemOs.SubItems.Add(SystemInfo.Get("Win32_OperatingSystem","Caption") + " - " + SystemInfo.Get("Win32_OperatingSystem","Version"));

ListViewItem itemCpu = lvSystemInfo.Items.Add("CPU");
itemCpu.SubItems.Add(SystemInfo.Get("Win32_Processor","Name"));

ListViewItem itemMem = lvSystemInfo.Items.Add("内存");
itemMem.SubItems.Add(Convert.ToString(Convert.ToInt32(SystemInfo.Get("Win32_OperatingSystem","TotalVisibleMemorySize"))/1024)+"M");

ListViewItem itemIis = lvSystemInfo.Items.Add("IIS");
FileVersionInfo fviIis = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory+"\\inetsrv\\asp.dll"); 
itemIis.SubItems.Add(fviIis.ProductName + " - " + fviIis.ProductVersion);

FileVersionInfo fviIe = FileVersionInfo.GetVersionInfo(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)+"\\Internet Explorer\\IEXPLORE.EXE");
ListViewItem itemIe = lvSystemInfo.Items.Add("IE");
itemIe.SubItems.Add(fviIe.ProductVersion); string[] dir = Directory.GetDirectories(SystemInfo.Get("Win32_OperatingSystem","WindowsDirectory")+"\\Microsoft.NET\\Framework","v*.*");
ListViewItem itemDotnet = lvSystemInfo.Items.Add(".NET Framework");
StringBuilder sb = new StringBuilder(255);
int index = 0;
foreach(string s in dir)
{
index = s.LastIndexOf("\\");
sb.Append(s.Substring(index+1,s.Length - index - 1));
sb.Append(" , ");
}
itemDotnet.SubItems.Add(sb.ToString(0,sb.Length-2)); sb.Remove(0,sb.Length);
if(fviIis.ProductMajorPart<5)sb.Append("IIS的版本至少要5.0或以上,");
if(fviIe.ProductMajorPart<6)sb.Append("IE的版本至少要6.0或以上,");
if(sb.Length>0)
{
sb.Append("请单击“取消”按钮,退出安装程序。");
strPrompt.Text = sb.ToString();
canNext = false;
}
else
{
canNext = true;
}
}这是SystemInfo.Get的方法的内容:
using System.Management;
public static string Get(string sInfoName,string sColName)
{
if(sInfoName=="")return "";
object myValue = ""; try
{
SelectQuery query = new SelectQuery(sInfoName); ManagementObjectSearcher searcher = new ManagementObjectSearcher(query); 
ManagementObjectCollection myCollection = searcher.Get(); myCollection = searcher.Get();
foreach(ManagementObject myMgmtObj in myCollection) 
{  
PropertyData Property = myMgmtObj.Properties[sColName];
myValue = Property.Value;
}
}
catch{}
return Convert.ToString(myValue);
}

解决方案 »

  1.   

    对于IIS版本号的读取,是通过FileVersionInfo得到的。对于.net framework的版本号,是通过看文件夹目录名称判断的。不过这个方法不一定准确。
    从前csdn上很多高手讨论过这个问题,“好象”没有什么太好的办法吧?
      

  2.   

    判断注册表阿!!HKEY_CLASSES_ROOT\Installer\Products\DDE7F2BCF1D91C3409CFF425AE1E271A
    ProductName Microsoft .NET Framework 1.1