recognizing devices from my pc using WMI

it recognizes some devices, but not all of them...

Page 1 of 1

1 Replies - 2712 Views - Last Post: 18 September 2008 - 02:33 PM Rate Topic: -----

#1 elijah_carrillo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-September 08

recognizing devices from my pc using WMI

Post icon  Posted 13 September 2008 - 04:38 PM

Hello! Everybody
I need to recognize all devices connected to mi pc, but some classes from WMI don't return any value, like the information about the FAN , BaseBoard and the Battery, I'd like to know WHY?
this is mi code, it uses a button and a TreeView, please I need some help.

[code]
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Management;

namespace reconoce_dispositivos
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TreeView treeView1;

private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}


protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.treeView1 = new System.Windows.Forms.TreeView();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(272, 56);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(80, 23);
this.button1.TabIndex = 0;
this.button1.Text = "ver hardware";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// treeView1
//
this.treeView1.ImageIndex = -1;
this.treeView1.Location = new System.Drawing.Point(8, 8);
this.treeView1.Name = "treeView1";
this.treeView1.SelectedImageIndex = -1;
this.treeView1.Size = new System.Drawing.Size(256, 320);
this.treeView1.TabIndex = 1;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(360, 334);
this.Controls.Add(this.treeView1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}



private void button1_Click(object sender, System.EventArgs e)
{
ManagementObjectSearcher dis = new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_DiskDrive");
TreeNode a = treeView1.Nodes.Add("Informacion de DiskDrive");
foreach (ManagementObject mo in dis.Get())
{
try
{

a.Nodes.Add("nombre:"+mo["name"]);
a.Nodes.Add("Availability"+mo["Availability"]);
a.Nodes.Add("BytesPerSector"+mo["BytesPerSector"]);
a.Nodes.Add("Capabilities"+mo["Capabilities"]);
a.Nodes.Add("CapabilityDescriptions"+mo["CapabilityDescriptions"]);
a.Nodes.Add("Caption"+mo["Caption"]);
a.Nodes.Add("CompressionMethod"+mo["CompressionMethod"]);
a.Nodes.Add("ConfigManagerErrorCode"+mo["ConfigManagerErrorCode"]);
a.Nodes.Add("ConfigManagerUserConfig"+mo["ConfigManagerUserConfig"]);
a.Nodes.Add("CreationClassName"+mo["CreationClassName"]);
a.Nodes.Add("DefaultBlockSize"+mo["DefaultBlockSize"]);
a.Nodes.Add("Description"+mo["Description"]);
a.Nodes.Add("DeviceID"+mo["DeviceID"]);
a.Nodes.Add("ErrorCleared"+mo["ErrorCleared"]);
a.Nodes.Add("SCSILogicalUnit"+mo["SCSILogicalUnit"]);
a.Nodes.Add("ErrorDescription"+mo["ErrorDescription"]);
a.Nodes.Add("ErrorMethodology"+mo["ErrorMethodology"]);
a.Nodes.Add("FirmwareRevision"+mo["FirmwareRevision"]);
a.Nodes.Add("InterfaceType"+mo["InterfaceType"]);
a.Nodes.Add("LastErrorCode"+mo["LastErrorCode"]);
a.Nodes.Add("Manufacturer"+mo["Manufacturer"]);
a.Nodes.Add("MaxBlockSize"+mo["MaxBlockSize"]);
a.Nodes.Add("MaxMediaSize"+mo["MaxMediaSize"]);
a.Nodes.Add("MediaLoaded"+mo["MediaLoaded"]);
a.Nodes.Add("SCSIBus"+mo["SCSIBus"]);
a.Nodes.Add("MediaType"+mo["MediaType"]);
a.Nodes.Add("MinBlockSize"+mo["MinBlockSize"]);
a.Nodes.Add("Model"+mo["Model"]);
a.Nodes.Add("NeedsCleaning"+mo["NeedsCleaning"]);
a.Nodes.Add("NumberOfMediaSupported"+mo["NumberOfMediaSupported"]);
a.Nodes.Add("Partitions"+mo["Partitions"]);
a.Nodes.Add("SCSIPort"+mo["SCSIPort"]);
a.Nodes.Add("Partitions"+mo["Partitions"]);
a.Nodes.Add("Partitions"+mo["Partitions"]);
a.Nodes.Add("Partitions"+mo["Partitions"]);
a.Nodes.Add("SCSITargetId"+mo["SCSITargetId"]);
a.Nodes.Add("SectorsPerTrack"+mo["SectorsPerTrack"]);
a.Nodes.Add("SerialNumber"+mo["SerialNumber"]);
a.Nodes.Add("Size"+mo["Size"]);
a.Nodes.Add("Status"+mo["Status"]);
a.Nodes.Add("SystemCreationClassName"+mo["SystemCreationClassName"]);
a.Nodes.Add("SystemName"+mo["SystemName"]);
a.Nodes.Add("TotalHeads"+mo["TotalHeads"]);
a.Nodes.Add("TotalSectors"+mo["TotalSectors"]);
a.Nodes.Add("TotalTracks"+mo["TotalTracks"]);
}
catch {}

}

ManagementObjectSearcher key = new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_KeyBoard");
TreeNode b = treeView1.Nodes.Add("Informacion de KeyBoard");
foreach (ManagementObject mo in key.Get())
{
try
{

b.Nodes.Add("nombre:"+mo["name"]);
b.Nodes.Add("Availability:"+mo["Availability"]);
b.Nodes.Add("Caption:"+mo["Caption"]);
b.Nodes.Add("ConfigManagerErrorCode:"+mo["ConfigManagerErrorCode"]);
b.Nodes.Add("ConfigManagerUserConfig:"+mo["ConfigManagerUserConfig"]);
b.Nodes.Add("CreationClassName:"+mo["CreationClassName"]);
b.Nodes.Add("Description:"+mo["Description"]);
b.Nodes.Add("DeviceID:"+mo["DeviceID"]);
b.Nodes.Add("ErrorCleared:"+mo["ErrorCleared"]);
b.Nodes.Add("Layout:"+mo["Layout"]);
b.Nodes.Add("NumberOfFunctionKeys:"+mo["NumberOfFunctionKeys"]);
b.Nodes.Add("Status:"+mo["Status"]);
b.Nodes.Add("SystemCreationClassName:"+mo["SystemCreationClassName"]);
b.Nodes.Add("SystemName:"+mo["SystemName"]);
}
catch {}


}
ManagementObjectSearcher fan = new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_Fan");
TreeNode c = treeView1.Nodes.Add("Informacion de Fan");
foreach (ManagementObject mo in fan.Get())
{
try
{
c.Nodes.Add("nombre:"+mo["name"]);
c.Nodes.Add("ActiveCooling:"+mo["ActiveCooling"]);
c.Nodes.Add("Availability:"+mo["Availability"]);
c.Nodes.Add("Caption:"+mo["Caption"]);
c.Nodes.Add("ConfigManagerErrorCode:"+mo["ConfigManagerErrorCode"]);
c.Nodes.Add("ConfigManagerUserConfig:"+mo["ConfigManagerUserConfig"]);
c.Nodes.Add("CreationClassName:"+mo["CreationClassName"]);
c.Nodes.Add("Description:"+mo["Description"]);
c.Nodes.Add("DesiredSpeed:"+mo["DesiredSpeed"]);
c.Nodes.Add("DeviceID:"+mo["DeviceID"]);
c.Nodes.Add("PowerManagementSupported:"+mo["PowerManagementSupported"]);
c.Nodes.Add("Status:"+mo["Status"]);
c.Nodes.Add("SystemCreationClassName:"+mo["SystemCreationClassName"]);
c.Nodes.Add("SystemName:"+mo["SystemName"]);
c.Nodes.Add("VariableSpeed:"+mo["VariableSpeed"]);
}
catch {}

}

ManagementObjectSearcher memo = new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_PhysicalMemory");
TreeNode d = treeView1.Nodes.Add("Informacion de PhysicalMemory");
foreach (ManagementObject mo in memo.Get())
{
try
{
d.Nodes.Add("nombre:"+mo["name"]);
d.Nodes.Add("BankLabel:"+mo["BankLabel"]);
d.Nodes.Add("Capacity:"+mo["Capacity"]);
d.Nodes.Add("Caption:"+mo["Caption"]);
d.Nodes.Add("CreationClassName:"+mo["CreationClassName"]);
d.Nodes.Add("DataWidth:"+mo["DataWidth"]);
d.Nodes.Add("Description:"+mo["Description"]);
d.Nodes.Add("DeviceLocator:"+mo["DeviceLocator"]);
d.Nodes.Add("FormFactor:"+mo["FormFactor"]);
d.Nodes.Add("HotSwappable:"+mo["HotSwappable"]);
d.Nodes.Add("InstallDate:"+mo["InstallDate"]);
d.Nodes.Add("InterleaveDataDepth:"+mo["InterleaveDataDepth"]);
d.Nodes.Add("InterleavePosition:"+mo["InterleavePosition"]);
d.Nodes.Add("Manufacturer:"+mo["Manufacturer"]);
d.Nodes.Add("MemoryType:"+mo["MemoryType"]);
d.Nodes.Add("Model:"+mo["Model"]);
d.Nodes.Add("PartNumber:"+mo["PartNumber"]);
d.Nodes.Add("PositionInRow:"+mo["PositionInRow"]);
d.Nodes.Add("PoweredOn:"+mo["PoweredOn"]);
d.Nodes.Add("Removable:"+mo["Removable"]);
d.Nodes.Add("Replaceable:"+mo["Replaceable"]);
d.Nodes.Add("SerialNumber:"+mo["SerialNumber"]);
d.Nodes.Add("SKU:"+mo["SKU"]);
d.Nodes.Add("Speed:"+mo["Speed"]);
d.Nodes.Add("Status:"+mo["Status"]);
d.Nodes.Add("Tag:"+mo[" Tag"]);
d.Nodes.Add("TotalWidth:"+mo[" TotalWidth"]);
d.Nodes.Add("Version:"+mo[" Version"]);
}
catch {}

}

ManagementObjectSearcher board = new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_BaseBoard");
TreeNode k = treeView1.Nodes.Add("Informacion de BaseBoard");
foreach (ManagementObject mo in board.Get())
{
try
{

k.Nodes.Add("nombrk:"+mo["namk"]);
k.Nodes.Add("Caption:"+mo["Caption"]);
k.Nodes.Add("Dkscription:"+mo["Dkscription"]);
k.Nodes.Add("Hkight:"+mo["Hkight"]);
k.Nodes.Add("HostingBoard:"+mo["HostingBoard"]);
k.Nodes.Add("HotSwappablk:"+mo["HotSwappablk"]);
k.Nodes.Add("InstallDatk:"+mo["InstallDatk"]);
k.Nodes.Add("Manufacturkr:"+mo["Manufacturkr"]);
k.Nodes.Add("Modkl:"+mo["Modkl"]);
k.Nodes.Add("PartNumbkr:"+mo["PartNumbkr"]);
k.Nodes.Add("PowkrkdOn:"+mo["PowkrkdOn"]);
k.Nodes.Add("Product:"+mo["Product"]);
k.Nodes.Add("Rkmovablk:"+mo["Rkmovablk"]);
k.Nodes.Add("Rkplackablk:"+mo["Rkplackablk"]);
k.Nodes.Add("RkquirkmkntsDkscription:"+mo["RkquirkmkntsDkscription"]);
k.Nodes.Add("RkquirksDaughtkrBoard:"+mo["RkquirksDaughtkrBoard"]);
k.Nodes.Add("SkrialNumbkr:"+mo["SkrialNumbkr"]);
k.Nodes.Add("SKU:"+mo["SKU"]);
k.Nodes.Add("SlotLayout:"+mo["SlotLayout"]);
k.Nodes.Add("Status:"+mo["Status"]);
k.Nodes.Add("Tag:"+mo["Tag"]);
k.Nodes.Add("Vkrsion:"+mo["Vkrsion"]);
k.Nodes.Add("Wkight:"+mo["Wkight"]);
k.Nodes.Add("Width:"+mo["Width"]);
}
catch {}


}

ManagementObjectSearcher bat = new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_Battery");
TreeNode f = treeView1.Nodes.Add("Informacion de Battery");
foreach (ManagementObject mo in bat.Get())
{
try
{
f.Nodes.Add("nombre:"+mo["name"]);
f.Nodes.Add("Availability:"+mo["Availability"]);
f.Nodes.Add("BatteryRechargeTime:"+mo["BatteryRechargeTime"]);
f.Nodes.Add("BatteryStatus:"+mo["BatteryStatus"]);
f.Nodes.Add("Caption:"+mo["Caption"]);
f.Nodes.Add("Chemistry:"+mo["Chemistry"]);
f.Nodes.Add("ConfigManagerUserConfig:"+mo["ConfigManagerUserConfig"]);
f.Nodes.Add("Description:"+mo["Description"]);
f.Nodes.Add("DesignCapacity:"+mo["DesignCapacity"]);
f.Nodes.Add("DesignVoltage:"+mo["DesignVoltage"]);
f.Nodes.Add("DeviceID:"+mo["DeviceID"]);
f.Nodes.Add("EstimatedChargeRemaining:"+mo["EstimatedChargeRemaining"]);
f.Nodes.Add("EstimatedRunTime:"+mo["EstimatedRunTime"]);
f.Nodes.Add("ExpectedBatteryLife:"+mo["ExpectedBatteryLife"]);
f.Nodes.Add("ExpectedLife:"+mo["ExpectedLife"]);
f.Nodes.Add("FullChargeCapacity:"+mo["FullChargeCapacity"]);
f.Nodes.Add("MaxRechargeTime:"+mo["MaxRechargeTime"]);
f.Nodes.Add("PNPDeviceID:"+mo["PNPDeviceID"]);
f.Nodes.Add("PowerManagementSupported:"+mo["PowerManagementSupported"]);
f.Nodes.Add("SmartBatteryVersion:"+mo["SmartBatteryVersion"]);
f.Nodes.Add("Status:"+mo["Status"]);
f.Nodes.Add("SystemCreationClassName:"+mo["SystemCreationClassName"]);
f.Nodes.Add("TimeOnBattery:"+mo["TimeOnBattery"]);
f.Nodes.Add("TimeToFullCharge:"+mo["TimeToFullCharge"]);
}
catch {}



}

ManagementObjectSearcher cd = new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_CDROMDrive");

TreeNode g = treeView1.Nodes.Add("Informacion de CDROMDrive");
foreach (ManagementObject mo in cd.Get())
{
try
{
g.Nodes.Add("nombre:"+mo["Name"]);
g.Nodes.Add("Availability:"+mo["Availability"]);
g.Nodes.Add("Caption:"+mo["Caption"]);
g.Nodes.Add("CompressionMethod:"+mo["CompressionMethod"]);
g.Nodes.Add("ConfigManagerUserConfig:"+mo["ConfigManagerUserConfig"]);
g.Nodes.Add("CreationClassName:"+mo["CreationClassName"]);
g.Nodes.Add("DefaultBlockSize:"+mo["DefaultBlockSize"]);
g.Nodes.Add("Description:"+mo["Description"]);
g.Nodes.Add("DeviceID:"+mo["DeviceID"]);
g.Nodes.Add("Drive:"+mo["Drive"]);
g.Nodes.Add("DriveIntegrity:"+mo["DriveIntegrity"]);
g.Nodes.Add("FileSystemFlags:"+mo["FileSystemFlags"]);
g.Nodes.Add("FileSystemFlagsEx:"+mo["FileSystemFlagsEx"]);
g.Nodes.Add("Id:"+mo["Id"]);
g.Nodes.Add("Manufacturer:"+mo["Manufacturer"]);
g.Nodes.Add("MaxBlockSize:"+mo["MaxBlockSize"]);
g.Nodes.Add("MaximumComponentLength:"+mo["MaximumComponentLength"]);
g.Nodes.Add("MaxMediaSize:"+mo["MaxMediaSize"]);
g.Nodes.Add("MediaLoaded:"+mo["MediaLoaded"]);
g.Nodes.Add("MfrAssignedRevisionLevel:"+mo["MfrAssignedRevisionLevel"]);
g.Nodes.Add("MinBlockSize:"+mo["MinBlockSize"]);
g.Nodes.Add("NeedsCleaning:"+mo["NeedsCleaning"]);
g.Nodes.Add("NumberOfMediaSupported:"+mo["NumberOfMediaSupported"]);
g.Nodes.Add("PNPDeviceID:"+mo["PNPDeviceID"]);
g.Nodes.Add("PowerManagementSupported:"+mo["PowerManagementSupported"]);
g.Nodes.Add("RevisionLevel:"+mo["RevisionLevel"]);
g.Nodes.Add("SCSIBus:"+mo["SCSIBus"]);
g.Nodes.Add("SCSILogicalUnit:"+mo["SCSILogicalUnit"]);
g.Nodes.Add("SCSIPort:"+mo["SCSIPort"]);
g.Nodes.Add("SCSITargetId:"+mo["SCSITargetId"]);
g.Nodes.Add("SerialNumber:"+mo["SerialNumber"]);
g.Nodes.Add("Size:"+mo["Size"]);
g.Nodes.Add("Status:"+mo["Status"]);
g.Nodes.Add("TransferRate:"+mo["TransferRate"]);
g.Nodes.Add("VolumeName:"+mo["VolumeName"]);
g.Nodes.Add("VolumeSerialNumber:"+mo["VolumeSerialNumber"]);
}
catch {}

}


ManagementObjectSearcher desk = new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_DesktopMonitor");
TreeNode h = treeView1.Nodes.Add("Informacion de DeskDtopMonitor");
foreach (ManagementObject mo in desk.Get())
{
try
{
h.Nodes.Add("nombre:"+mo["Name"]);
h.Nodes.Add("Availability:"+mo["Availability"]);
h.Nodes.Add("Bandwidth:"+mo["Bandwidth"]);
h.Nodes.Add("Caption:"+mo["Caption"]);
h.Nodes.Add("ConfigManagerErrorCode:"+mo["ConfigManagerErrorCode"]);
h.Nodes.Add("ConfigManagerUserConfig:"+mo["ConfigManagerUserConfig"]);
h.Nodes.Add("Description:"+mo["Description"]);
h.Nodes.Add("DeviceID:"+mo["DeviceID"]);
h.Nodes.Add("DisplayType:"+mo["DisplayType"]);
h.Nodes.Add("ErrorCleared:"+mo["ErrorCleared"]);
h.Nodes.Add("IsLocked:"+mo["IsLocked"]);
h.Nodes.Add("LastErrorCode:"+mo["LastErrorCode"]);
h.Nodes.Add("MonitorManufacturer:"+mo["MonitorManufacturer"]);
h.Nodes.Add("MonitorType:"+mo["MonitorType"]);
h.Nodes.Add("PixelsPerXLogicalInch:"+mo["PixelsPerXLogicalInch"]);
h.Nodes.Add("PixelsPerYLogicalInch:"+mo["PixelsPerYLogicalInch"]);
h.Nodes.Add("PNPDeviceID:"+mo["PNPDeviceID"]);
h.Nodes.Add("PowerManagementSupported:"+mo["PowerManagementSupported"]);
h.Nodes.Add("ScreenHeight:"+mo["ScreenHeight"]);
h.Nodes.Add("ScreenWidth:"+mo["ScreenWidth"]);
h.Nodes.Add("StatusInfo:"+mo["StatusInfo"]);
h.Nodes.Add("SystemCreationClassName:"+mo["SystemCreationClassName"]);
}
catch {}
}



ManagementObjectSearcher flop = new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_FloppyDrive");
TreeNode i = treeView1.Nodes.Add("Informacion de FloppyDrive");
foreach (ManagementObject mo in flop.Get())
{
try
{
i.Nodes.Add("nombre:"+mo["Name"]);
i.Nodes.Add("Availability:"+mo["Availability"]);
i.Nodes.Add("Caption:"+mo["Caption"]);
i.Nodes.Add("CompressionMethod:"+mo["CompressionMethod"]);
i.Nodes.Add("ConfigManagerErrorCode:"+mo["ConfigManagerErrorCode"]);
i.Nodes.Add("ConfigManagerUserConfig:"+mo["ConfigManagerUserConfig"]);
i.Nodes.Add("CreationClassName:"+mo["CreationClassName"]);
i.Nodes.Add("DefaultBlockSize:"+mo["DefaultBlockSize"]);
i.Nodes.Add("Description:"+mo["Description"]);
i.Nodes.Add("DeviceID:"+mo["DeviceID"]);
i.Nodes.Add("ErrorMethodology:"+mo["ErrorMethodology"]);
i.Nodes.Add("Manufacturer:"+mo["Manufacturer"]);
i.Nodes.Add("MaxBlockSize:"+mo["MaxBlockSize"]);
i.Nodes.Add("MaxMediaSize:"+mo["MaxMediaSize"]);
i.Nodes.Add("MinBlockSize:"+mo["MinBlockSize"]);
i.Nodes.Add("NeedsCleaning:"+mo["NeedsCleaning"]);
i.Nodes.Add("NumberOfMediaSupported:"+mo["NumberOfMediaSupported"]);
i.Nodes.Add("PNPDeviceID:"+mo["PNPDeviceID"]);
 

Is This A Good Question/Topic? 0
  • +

Replies To: recognizing devices from my pc using WMI

#2 djkitt  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 189
  • Joined: 22-May 08

Re: recognizing devices from my pc using WMI

Posted 18 September 2008 - 02:33 PM

Hello there Elijah,

Looking at the code segment you provided it looks like it should be working, although it looks like not all your code was posted.

I added your 'fan' code into my own WMI browser and it worked fine, showing both my fans.

This post has been edited by djkitt: 18 September 2008 - 02:34 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1