472,187 Members | 1,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,187 software developers and data experts.

Read the Device manager programatically

I was wondering if there is any way for me to read the device manager in my
C# program? I have a program that crashes when some third party hardware is
not installed or is set to the wrong port and I could solve that problem if
I could read a couple entries from the registry.
Thanks in advance,
~Logan
Nov 15 '05 #1
5 33880
You could use WMI for this.
See the namespace System.Management.Instrumentation
-----Original Message-----
I was wondering if there is any way for me to read the device manager in myC# program? I have a program that crashes when some third party hardware isnot installed or is set to the wrong port and I could solve that problem ifI could read a couple entries from the registry.
Thanks in advance,
~Logan
.

Nov 15 '05 #2
That looks like it would have what I need but WMI has such a large scope I
was wondering if you might be able to point me to a specific part of WMI?
Thanks for all of your help,
~Logan
"Sunil" <an*******@discussions.microsoft.com> wrote in message
news:0e****************************@phx.gbl...
You could use WMI for this.
See the namespace System.Management.Instrumentation
-----Original Message-----
I was wondering if there is any way for me to read the

device manager in my
C# program? I have a program that crashes when some

third party hardware is
not installed or is set to the wrong port and I could

solve that problem if
I could read a couple entries from the registry.
Thanks in advance,
~Logan
.

Nov 15 '05 #3
What stops you to simply read the Registry?

Willy.

"Logan McKinley" <lo***@globalweb.net> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
I was wondering if there is any way for me to read the device manager in my
C# program? I have a program that crashes when some third party hardware is
not installed or is set to the wrong port and I could solve that problem if
I could read a couple entries from the registry.
Thanks in advance,
~Logan

Nov 15 '05 #4
I am not sure where in the registry that information is located. I need to
make sure an installed serial port (USB/Serial Port emulator) is available
and the device description. So an enumeration of serial ports with their
descriptions would be perfect.
Thanks,
~Logan
----- Original Message -----
From: "Willy Denoyette [MVP]" <wi*************@pandora.be>
Newsgroups:
microsoft.public.dotnet.framework,microsoft.public .dotnet.languages.csharp
Sent: Wednesday, October 29, 2003 1:23 PM
Subject: Re: Read the Device manager programatically

What stops you to simply read the Registry?

Willy.

"Logan McKinley" <lo***@globalweb.net> wrote in message

news:%2****************@TK2MSFTNGP11.phx.gbl...
I was wondering if there is any way for me to read the device manager in my C# program? I have a program that crashes when some third party hardware is not installed or is set to the wrong port and I could solve that problem if I could read a couple entries from the registry.
Thanks in advance,
~Logan


Nov 15 '05 #5
Logan,

Herewith a small console program that enumerates all devices connected to the system and print their respective properties.
If you find your device(s) description in the output , it will be possible to refine the query for just the devices you are
interested in.
using System;
using System.Management;
// Enum Pnp Registered devices using WMI class Win32_PnPentity
class App {
public static void Main() {
ManagementPath path = new ManagementPath();
ManagementClass devs = null;
path.Server = ".";
path.NamespacePath = @"root\CIMV2";
path.RelativePath = @"Win32_PnPentity";
using(devs = new ManagementClass(new ManagementScope(path), path, new ObjectGetOptions(null, new TimeSpan(0,0,0,2), true)))
{
ManagementObjectCollection moc = devs.GetInstances();
foreach(ManagementObject mo in moc) {

PropertyDataCollection devsProperties = mo.Properties;
foreach (PropertyData devProperty in devsProperties ) {
if (devProperty.Type == CimType.DateTime) {
if(devProperty.Value != null)
Console.WriteLine("Date {0}", ToDateTime(devProperty.Value.ToString()));
}
else
Console.WriteLine("Property = {0}\t Value = {1}",
devProperty.Name, devProperty.Value);
}

RelatedObjectQuery relatedQuery = new RelatedObjectQuery
("associators of {Win32_PnPEntity.DeviceID='" + mo["DeviceID"]+ "'}");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(new ManagementScope(path),relatedQuery);
foreach (ManagementObject mob in searcher.Get()) {

Console.WriteLine("--------------------------->>>>>>");
Console.WriteLine(mob["Description"]);

}
Console.WriteLine("----------------------");
}

}

}
// Converts a given datetime in DMTF format to System.DateTime object.
static System.DateTime ToDateTime(string dmtfDate) {
int year = System.DateTime.MinValue.Year;
int month = System.DateTime.MinValue.Month;
int day = System.DateTime.MinValue.Day;
int hour = System.DateTime.MinValue.Hour;
int minute = System.DateTime.MinValue.Minute;
int second = System.DateTime.MinValue.Second;
long ticks = 0;
string dmtf = dmtfDate;
System.DateTime datetime = System.DateTime.MinValue;
string tempString = System.String.Empty;
if ((dmtf == null)) {
throw new System.ArgumentOutOfRangeException();
}
if ((dmtf.Length == 0)) {
throw new System.ArgumentOutOfRangeException();
}
if ((dmtf.Length != 25)) {
throw new System.ArgumentOutOfRangeException();
}
try {
tempString = dmtf.Substring(0, 4);
if (("****" != tempString)) {
year = System.Int32.Parse(tempString);
}
tempString = dmtf.Substring(4, 2);
if (("**" != tempString)) {
month = System.Int32.Parse(tempString);
}
tempString = dmtf.Substring(6, 2);
if (("**" != tempString)) {
day = System.Int32.Parse(tempString);
}
tempString = dmtf.Substring(8, 2);
if (("**" != tempString)) {
hour = System.Int32.Parse(tempString);
}
tempString = dmtf.Substring(10, 2);
if (("**" != tempString)) {
minute = System.Int32.Parse(tempString);
}
tempString = dmtf.Substring(12, 2);
if (("**" != tempString)) {
second = System.Int32.Parse(tempString);
}
tempString = dmtf.Substring(15, 6);
if (("******" != tempString)) {
ticks = (System.Int64.Parse(tempString)
* (System.TimeSpan.TicksPerMillisecond / 1000));
}
if (((((((((year < 0)
|| (month < 0))
|| (day < 0))
|| (hour < 0))
|| (minute < 0))
|| (minute < 0))
|| (second < 0))
|| (ticks < 0))) {
throw new System.ArgumentOutOfRangeException();
}
}
catch (System.Exception e) {
e = e;
throw new System.ArgumentOutOfRangeException();
}
datetime = new System.DateTime(year, month, day, hour, minute, second, 0);
datetime = datetime.AddTicks(ticks);
System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datet ime);
int UTCOffset = 0;
long OffsetToBeAdjusted = 0;
long OffsetMins = (tickOffset.Ticks / System.TimeSpan.TicksPerMinute);
tempString = dmtf.Substring(22, 3);
if ((tempString != "******")) {
tempString = dmtf.Substring(21, 4);
try {
UTCOffset = System.Int32.Parse(tempString);
}
catch (System.Exception e) {
e = e;
throw new System.ArgumentOutOfRangeException();
}
OffsetToBeAdjusted = (OffsetMins - UTCOffset);
datetime = datetime.AddMinutes(OffsetToBeAdjusted);
}
return datetime;
}
}

Willy.

"Logan McKinley" <lo***@globalweb.net> wrote in message news:O5*************@TK2MSFTNGP11.phx.gbl...
I am not sure where in the registry that information is located. I need to
make sure an installed serial port (USB/Serial Port emulator) is available
and the device description. So an enumeration of serial ports with their
descriptions would be perfect.
Thanks,
~Logan
----- Original Message -----
From: "Willy Denoyette [MVP]" <wi*************@pandora.be>
Newsgroups:
microsoft.public.dotnet.framework,microsoft.public .dotnet.languages.csharp
Sent: Wednesday, October 29, 2003 1:23 PM
Subject: Re: Read the Device manager programatically

What stops you to simply read the Registry?

Willy.

"Logan McKinley" <lo***@globalweb.net> wrote in message

news:%2****************@TK2MSFTNGP11.phx.gbl...
I was wondering if there is any way for me to read the device manager in my C# program? I have a program that crashes when some third party hardware is not installed or is set to the wrong port and I could solve that problem if I could read a couple entries from the registry.
Thanks in advance,
~Logan



Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jayderk | last post by:
I was wondering if anyone knows of a way to open the device manager, OR system properties? thanks in advanced, Jay
1
by: donler | last post by:
Does anyone know how to read from the Device Manager. I would like to get a list of all devices and if possible, get some information about each...
1
by: hayworth | last post by:
Does anyone have any VB.Net code to get the devices listed / enumerated in the Device Manager listing. I'm trying to figure out if a device...
1
by: Cameron K | last post by:
ok i haven't had internet in about 3 months but i just got dial up at home and my modem wasn't responding so what do i find in the device...
2
by: RootSpy2006 | last post by:
Hi All, Problem Definition: --------------------- Microsoft Wirelss Keyboard works in BIOS but does not work when booting into windows. ...
1
by: karan.shashi | last post by:
Hello to all the C# gurus :), I'm interested in whether it's possible to enable and/or disable devices in the device manager programmatically...
0
by: vivelafaq | last post by:
Hi everyone, I want to find a way to get the label of a com port like displayed in the device manager in ports : e.g : PC | _Ports (COM &...
3
by: rosath | last post by:
I want to select a device in device manager based on the name of the device. How can I achieve this using perl? Any help is truely appreciated.
0
by: =?Utf-8?B?QmV2eV9KZXRlcg==?= | last post by:
Using XP Pro as an administrator. Experiencing 3 problems: 1) Device Manager is empty in both normal & safe modes, 2) F8 will not take me into...
0
by: antdb | last post by:
On August 26, the Global Distributed Cloud Conference was held in Beijing, which was dedicated to promoting the development of distributed cloud...
0
by: pddon | last post by:
1. Brief introduction PDDON is a free online drawing tool that supports low code. It can be used to draw architecture diagram, flow diagram, UML,...
0
by: Saiars | last post by:
Hello! I wish to assemble a team of enthusiasts with the help of which we will create a strong social network so that everything is as we want in it....
0
by: antdb | last post by:
Recently, Forrester, an internationally renowned ICT research and consulting organization, recently released the Trend Report: Navigate The Data...
0
by: antdb | last post by:
Recently, the “Telecommunication Industry Database Adaptation Test Business Specification” and “Telecommunication Industry Database Adaptation Test...
7
by: bounthong | last post by:
Dear friends, I am using MS Access 2022 (office 365), I am having trouble with creating shortcut menu command for report. I tried to follow the same...
1
by: Computer0300 | last post by:
If I type !! in my query criteria and query deals with its value which may be (Like "" & "Raj Poot" & "") Or (Like "" & "Malak" & ""). Is it...
1
by: donraf | last post by:
I have a main form (Orders), a subform (OrderDetails) and a separate form (Products). The OrderDetails is a child form of Orders. Products form...
2
by: AshAccess | last post by:
I thought I posted this, but I can't find it anywhere, so I'm going to post it, again. I hope there's not some kind of delay, and they both show up!...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.