473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

CTD with some (very few) .NET 2.0 XP SP2 Users

When I instatiate the following class like so:

public static HardDrive theHD = new HardDrive();

in the program.cs, the program crashes to desktop for some users. Most have
no reported problem.

This is the class:

class HardDrive
{
public HardDrive()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT
* FROM Win32_DiskDrive");

if (searcher != null)
{
foreach (ManagementObject wmi_HD in searcher.Get())
{
Model = wmi_HD["Model"].ToString();
Type = wmi_HD["InterfaceType"].ToString();
break;
}
}
else
{
// Error
MessageBox.Show("Exiting: searcher == null.");
Application.Exit();
}

searcher = new ManagementObjectSearcher("SELECT * FROM
Win32_PhysicalMedia");

if (searcher != null)
{
foreach (ManagementObject wmi_HD in searcher.Get())
{
if (wmi_HD["SerialNumber"] == null)
SerialNo = "None";
else
SerialNo = wmi_HD["SerialNumber"].ToString();
break;
}
}
else
{
// Error
MessageBox.Show("Exiting: searcher2 == null.");
Application.Exit();
}
}

public string Model
{
get { return model; }
set { model = value; }
}

public string Type
{
get { return type; }
set { type = value; }
}

public string SerialNo
{
get { return serialNo; }
set { serialNo = value; }
}

private string model = null;
private string type = null;
private string serialNo = null;
}

anyone know why this might crash some users?

Patrick

Aug 8 '06 #1
1 1077
You may want to do two things. First check the values for null that you get from your ManagementObject. Ex:

string s = string.Empty;

if ( wmi_HD["Model"] != null )

s = wmi_HD["Model"].ToString()

2nd, consider some try...catch that will report the problem, but I think that by checking for null on the properties you'll have less problems already

Michael Klingensmith

http://www.seeknsnatch.com

"Stick" <St***@discussions.microsoft.comwrote in message news:FD**********************************@microsof t.com...
When I instatiate the following class like so:

public static HardDrive theHD = new HardDrive();

in the program.cs, the program crashes to desktop for some users. Most have
no reported problem.

This is the class:

class HardDrive
{
public HardDrive()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT
* FROM Win32_DiskDrive");

if (searcher != null)
{
foreach (ManagementObject wmi_HD in searcher.Get())
{
Model = wmi_HD["Model"].ToString();
Type = wmi_HD["InterfaceType"].ToString();
break;
}
}
else
{
// Error
MessageBox.Show("Exiting: searcher == null.");
Application.Exit();
}

searcher = new ManagementObjectSearcher("SELECT * FROM
Win32_PhysicalMedia");

if (searcher != null)
{
foreach (ManagementObject wmi_HD in searcher.Get())
{
if (wmi_HD["SerialNumber"] == null)
SerialNo = "None";
else
SerialNo = wmi_HD["SerialNumber"].ToString();
break;
}
}
else
{
// Error
MessageBox.Show("Exiting: searcher2 == null.");
Application.Exit();
}
}

public string Model
{
get { return model; }
set { model = value; }
}

public string Type
{
get { return type; }
set { type = value; }
}

public string SerialNo
{
get { return serialNo; }
set { serialNo = value; }
}

private string model = null;
private string type = null;
private string serialNo = null;
}

anyone know why this might crash some users?

Patrick
Aug 8 '06 #2

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

Similar topics

9
by: TPJ | last post by:
First I have to admit that my English isn't good enough. I'm still studying and sometimes I just can't express what I want to express. A few weeks ago I've written 'Python Builder' - a bash...
5
by: neil | last post by:
Hey, I'd really appreciate if you guys having C++ experience gave advice with some questions I'm pondering over... Books: What book do you recommend for someone about to approach the...
11
by: Lues | last post by:
Hi, I'm trying to protect some data in tables with encription (you know why, don't you ;)) I must confess that I'm not very expirienced in writing code, especially encription code. Can any...
1
by: Norman Fritag | last post by:
Hi there I have avoided to use active x controls because I thought they are causing more problems then they are doing any good. I a new application I would want to use the tree and list view...
193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
21
by: Jim | last post by:
I am trying to write an HTTP/HTTPS proxy server in VB.Net 2005. But, I don't really even know how the internal workings of a proxy should act. Does anyone have anything on the protocols used in...
13
by: groupy | last post by:
input: 1.5 million records table consisting users with 4 nvchar fields:A,B,C,D the problem: there are many records with dublicates A's or duplicates B's or duplicates A+B's or duplicates B+C+D's &...
52
by: robert | last post by:
I'm very pleased to announce that Foundations of F#, the first book to be published on the F# programming, will finish its first printing run, tomorrow, Friday 25th May. It should reach any...
4
by: adamwolf1965 | last post by:
On the page http://www.franklincar.org/index.html (which I did not build), some Firefox users are reporting that the "Franklin Vintage Photo Book" image towards the middle of the page (right below...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.