473,666 Members | 1,977 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.Manageme nt;
....
private string GetDiskSerial()
{
string strSerial = "";

SelectQuery selQuery = new SelectQuery("SE LECT * FROM
WIN32_DiskDrive ");
ManagementObjec tSearcher searchResult = new
ManagementObjec tSearcher(selQu ery);

foreach (ManagementObje ct item in searchResult.Ge t())
{
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 2588

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.Manageme nt;
...
private string GetDiskSerial()
{
string strSerial = "";

SelectQuery selQuery = new SelectQuery("SE LECT * FROM
WIN32_DiskDrive ");
ManagementObjec tSearcher searchResult = new
ManagementObjec tSearcher(selQu ery);

foreach (ManagementObje ct item in searchResult.Ge t())
{
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_LogicalDi sk, so the results may be different. When I
loop through the objects in my ManagementObjec tCollection, the results
are brought back in order of the drive letter assigned to it, so C:\,
D:\, etc. My guess is that Win32_LogicalDi sk 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
14064
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 operating system would be appropriate. However, I do not know how to retrieve the information. Could you help? Klaus
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 or later. How to retrieve those data on Win98/ME/2000/XP by using C#?
14
28137
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) Win32_PhysicalMedia (a class) property SerialNumber." I'm sorry to admit it bit I am really undereducated on how to incorporate some of the Windows SDK stuff into VBA apps. Anyone know of some sample code that will allow us to read the C drive hardware...
6
30702
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 serial number would do fine, but on Googling it seems that some of the sample code will now laways work on W2K, and not without administrator rights. Hence my question - how can I consistently get a UNIQUE PC identifier using vb.net 2003 - not...
0
8445
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8871
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8551
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8640
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6198
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
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 we have to send another system
2
2011
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.