473,473 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 34293
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 device. thx much
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 (it's actually a digital camera) is connected to the...
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 manager...NOTHING!!!! i have already tried turning plug and...
2
by: RootSpy2006 | last post by:
Hi All, Problem Definition: --------------------- Microsoft Wirelss Keyboard works in BIOS but does not work when booting into windows. Discovered Work-around: -----------------------------...
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 using C#. Anybody with some insight on this? I'm...
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 & LPT) | _CP210x USB to UART Bridge Controller (COM3).
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 Safe Mode but MSConfig will, & 3) Computer folder...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.