2014-11-02 123 views
-2

我有一些问题(c#)。使用c获取系统信息#

  1. 我可以检索从Win32的踢脚线一些主板的信息,但是当我想型号 但累积的错误。

  2. 我们如何获得Windows上安装的软件列表(如xp)。

  3. 我们如何获得Windows上安装的外围设备列表(包括详细信息)(如扫描仪,网络摄像头)。

  4. 如何获得总数直接数量的公羊(刚)。

+3

你可以找到所有这些问题的答案已经在SO。 – 2014-11-02 08:29:49

+0

虽然我回答了你应该让你的问题更清楚你确实使用了WMI并提供了一个代码示例。 – e4rthdog 2014-11-02 08:57:30

+0

我发现第一个问题的答案 - “模型是空白的”-tnx到e4rthdog – 2014-11-02 10:56:07

回答

1

使用WMI(我怀疑你已经在使用它):

  1. 型号为空白。尝试Manufacturer属性。同时获取Product属性以获取模型。

  2. 安装的软件:获取Win32_Product类。

  3. 尝试Win32_PnPSignedDriver类并重复遍历。

  4. 使用Win32_ComputerSystem类和得到TotalPhysicalMemory财产。

获取WMIEXPLORER并与之一起玩。LINK

样品为C#:

如果您需要连接到使用证书的远程计算机(strUserName中和strPassword变量):

private ManagementScope CreateNewManagementScope(string server) 
{ 
    string serverString = @"\\" + server + @"\root\cimv2"; 

    ManagementScope scope = new ManagementScope(serverString); 

    if (!chkUseCurrentUser.Checked) 
    { 
     ConnectionOptions options = new ConnectionOptions 
          { 
           Username = strUsername, 
           Password = strPassword, 
           Impersonation = ImpersonationLevel.Impersonate, 
           Authentication = AuthenticationLevel.PacketPrivacy 
          }; 
     scope.Options = options; 
    } 

    return scope; 
} 

获取服务:

private void GetServicesForComputer(string computerName) 
{ 
    ManagementScope scope = CreateNewManagementScope(computerName); 

    SelectQuery query = new SelectQuery("select * from Win32_Service"); 

    try 
    { 
     using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query)) 
     { 
      ManagementObjectCollection services = searcher.Get(); 

      List<string> serviceNames = 
       (from ManagementObject service in services select service["Caption"].ToString()).ToList(); 

      lstServices.DataSource = serviceNames; 
     } 
    } 
    catch (Exception exception) 
    { 
     lstServices.DataSource = null; 
     lstServices.Items.Clear(); 
     lblErrors.Text = exception.Message; 
     Console.WriteLine(Resources.MainForm_GetServicesForServer_Error__ + exception.Message); 
    } 
} 

从wmiexplorer一些屏幕:

enter image description here enter image description here enter image description here enter image description here