473,507 Members | 2,441 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieve disk serial number

I'm using the following code to retrieve the disk serial number of my hard
disk, but have nagging doubts as to whether it'll work on other machines.
Does anyone have experience of doing this who can advise whether I'm on
relatively safe ground here:

using System.Management;
....
private string GetDiskSerial()
{
string strSerial = "";

SelectQuery selQuery = new SelectQuery("SELECT * FROM
WIN32_DiskDrive");
ManagementObjectSearcher searchResult = new
ManagementObjectSearcher(selQuery);

foreach (ManagementObject item in searchResult.Get())
{
if (item["Signature"] != null)
{
strSerial = item["Signature"].ToString();
break;
}
}

return strSerial;
}

What I'm not sure of is the order in which disks are presented, so what
happens if there is more than one physical disk drive and what happens if
this is a diskless workstation.

I know I get the right result on my machine as the value returned matches
the one I see in the WMI browser.

Thanks
Steve
Sep 25 '06 #1
1 2543

Steve Barnett wrote:
I'm using the following code to retrieve the disk serial number of my hard
disk, but have nagging doubts as to whether it'll work on other machines.
Does anyone have experience of doing this who can advise whether I'm on
relatively safe ground here:

using System.Management;
...
private string GetDiskSerial()
{
string strSerial = "";

SelectQuery selQuery = new SelectQuery("SELECT * FROM
WIN32_DiskDrive");
ManagementObjectSearcher searchResult = new
ManagementObjectSearcher(selQuery);

foreach (ManagementObject item in searchResult.Get())
{
if (item["Signature"] != null)
{
strSerial = item["Signature"].ToString();
break;
}
}

return strSerial;
}

What I'm not sure of is the order in which disks are presented, so what
happens if there is more than one physical disk drive and what happens if
this is a diskless workstation.

I know I get the right result on my machine as the value returned matches
the one I see in the WMI browser.

Thanks
Steve
Steve,

I'm using Win32_LogicalDisk, so the results may be different. When I
loop through the objects in my ManagementObjectCollection, the results
are brought back in order of the drive letter assigned to it, so C:\,
D:\, etc. My guess is that Win32_LogicalDisk returns it in order of
partition/disk ID.

I would suspect that Win32_DiskDrive would do the same thing.

Hope that helps,
Clint

Sep 25 '06 #2

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

Similar topics

79
13963
by: Klaus Bonadt | last post by:
In order to protect software from being copied without licence, I would like to use something like a key, which fits only to the current system. The serial number of the CPU or the current...
1
507
by: jewelin | last post by:
I'd tried to retrieve the ID or Serial Number of main-board and hard-disk via WMI using C#, but failed. One friend suggested me with some codes calling WIN32 API, but only effective on WIN2000...
14
28077
by: Lauren Wilson | last post by:
Discovered this interesting comment on MSDN: "To programmatically obtain the hard disk's serial number that the manufacturer assigns, use the Windows Management Instrumentation (WMI)...
6
30685
by: Paul Bromley | last post by:
Ok - I have given up on trying to find the active IP address for a given PC. For licensing purposes I need to retrive a unique identifier from the PC that the program is installed on. The Hard disk...
0
7223
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
7485
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
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
5042
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
4702
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
3191
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
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
760
muto222
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.