views:

931

answers:

6

I want to get the hardwired serial number from the hard disk but NOT using WMI. I tried using WMI code, and it doesn't work on my machine for sure. So is there any alternative in .NET for finding the Serial Number of a physical hard disk?

+1  A: 

This should help get started:

How to get Physical HDD serial number without WMI

Regarding your problem with WMI not returning data; Are you sure how to the right privileges to get data from WMI? You can use WMI Tools to check/fix this.

Espo
I am running the code in the limited account mode. So I guess thats the problem. IS there any way I can elevate my privileges from within the limited account?
Xinxua
I don't think so. Wouldn't that miss the whole point of assigning privileges to users? Or if you know the admin-password, you can use the "runas" command.
Espo
A: 

You can use the:

GetVolumeInformation

Win32 API function to get this information, if you must avoid WMI. The linked page gives full the declaration signature (in both VB & C#) for the API function along with sample code.

CraigTP
Is it not returning the Volume serial number? I want the device serial number which does not change with formatting
Xinxua
@Xinxua - Sorry, you're correct. It returns the volume rather than the device serial. I think the only way to achieve this without using WMI is to call down into low-level OS functions called by C++/unmanaged code (as per the other Espo's answer), however, if you're running with limited Windows account privileges and WMI is failing (probably because of this) then I doubt that calling a C++ dll's functions from a .NET app will work either unless you can run/execute code as a higher privilege, and that would require the relevant access/passwords to do so.
CraigTP
A: 

You'll want to use WMI for this—this article has an example.

Mark B
A: 

Use WMI from Server Explorer in VS

  • Open Server explorer
  • Expand your machine
  • Expand management classes
  • Expand Disk Volumes
  • Select the drive
  • Drag it onto a form to see the generated code
  • Access the VolumeSerialNumber property in code
Johann Strydom
+3  A: 

Rough and ready:

using System;
using System.Management;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            ManagementClass mangnmt = new ManagementClass("Win32_LogicalDisk");
            ManagementObjectCollection mcol = mangnmt.GetInstances();
            string result = "";
            foreach (ManagementObject strt in mcol)
            {
                result += "Name              : " + Convert.ToString(strt["Name"]) + Environment.NewLine;
                result += "VolumeName        : " + Convert.ToString(strt["VolumeName"]) + Environment.NewLine;
                result += "VolumeSerialNumber: " + Convert.ToString(strt["VolumeSerialNumber"]) + Environment.NewLine;
                result += Environment.NewLine;
            }
            Console.Out.WriteLine(result);
            Console.In.ReadLine();
        }
    }
}

Note there are also other attributes you can use, and if you want the details for a specific disk you will need to do some processing on the results.

Hope that helps!

simonalexander2005
A: 

I am using hdd firmware track in my projects. I programmed behind the mdi form to look for hdd firmware number, then its looping on all the provided numbers of hdds of companies computers and if it matches anyone amongst these provided hdds firmware numbers, then run the applicatoin and load mdi form other wise provides a message "The application is not registed on this machine, please call Mr. Afridi to register this application on 00923339176357. My email address is [email protected]. I will send complete source code of fetching how to programm professionaly hdd firmware number and how to stop others by using your app illegaly.

One lovely thing that you should specify all the company computers hdd firmware at once and let the application first pick the hdd firmware number, store it in a variable and then pick the value of this variable(a string value) and loop it one by one with each hdd number by using OR logical operator. If it finds a matching number amongst the companies hdds numbers with variable value, then app should load main form(mdi) other wise notify the user for registration.

the sample code will be provided using vb6. You can easily programm later on in vb.net just by understanding how to call unmanaged code in to a managed .net application. In this case a .dll.

Mr. Afridi. (MCP.net,MCAD.net,MCSD.net,MCPD.net)

Munawar Shah Afridi