View Full Version : use c# to search for an hardware
keroed1
November 15, 2006, 09:39 AM
i want to integrate a sentinel hardware device with one of my applications that icreated, so i wanted to know if C# is able to check for hardwares that are plugged in on your machine, so i would love for anyone to tell me how to do this or send me a link of what to read up on to do this
crosswire
November 17, 2006, 03:31 PM
Example to find all cd rom drives Note add a refernce to the System.Management, in the dll part
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Management;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// This is to show how to use the SelectQuery object in the place of a SELECT
// statement.
SelectQuery query = new SelectQuery("Win32_CDROMDrive");
//ManagementObjectSearcher retrieves a collection of WMI objects based on
// the query.
ManagementObjectSearcher search = new ManagementObjectSearcher(query);
// Display each entry for Win32_timezone
txtOutput.Text = string.Empty;
foreach (ManagementObject info in search.Get())
{
txtOutput.Text += info["name"].ToString() + "\r\n"; //See class definition for more class Win32_CDROMDrive @ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_cdromdrive.asp
//txtOutput.Text += info["caption"].ToString() + "\r\n";
}
}
}
}
Reference
System.Management Namespace
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemManagement.asp?frame=true
Computer System Hardware Classes
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/computer_system_hardware_classes.asp?frame=true
101 C# Samples - Framework - Using WMI
keroed1
November 18, 2006, 11:12 AM
Example to find all cd rom drives Note add a refernce to the System.Management, in the dll part
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Management;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// This is to show how to use the SelectQuery object in the place of a SELECT
// statement.
SelectQuery query = new SelectQuery("Win32_CDROMDrive");
//ManagementObjectSearcher retrieves a collection of WMI objects based on
// the query.
ManagementObjectSearcher search = new ManagementObjectSearcher(query);
// Display each entry for Win32_timezone
txtOutput.Text = string.Empty;
foreach (ManagementObject info in search.Get())
{
txtOutput.Text += info["name"].ToString() + "\r\n"; //See class definition for more class Win32_CDROMDrive @ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_cdromdrive.asp
//txtOutput.Text += info["caption"].ToString() + "\r\n";
}
}
}
}
Reference
System.Management Namespace
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemManagement.asp?frame=true
Computer System Hardware Classes
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/computer_system_hardware_classes.asp?frame=true
101 C# Samples - Framework - Using WMI
wow thanks crosswire i going read though the links you sent me. i thought i was going to be forced to go the option of writing some scripts to try and accomplish.
in the System Management link is there a class i can use that can tell me if a specific hardware is pluged in like if serial cable is plugged into com port and attached to a device. going try and read through them as soon as i get back roun the pc
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.