473,395 Members | 1,624 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,395 software developers and data experts.

How to Get VolumeSerial Of Harddisk?

Hi everybody
I need to get serial number of harddist drive (C:\).

Here I tried some codes.

//**************
using System;

using System.Runtime.InteropServices;

namespace HanleyUretim

{

/// <summary>

///

/// </summary>

public class ManagerClass

{

public ManagerClass()

{

//

// TODO: Add constructor logic here

//

}

//public SerialReader sr=new SerialReader();
unsafe public string GetSerial()

{

//char[]

//long serial1=0;//=(int*)new int();

string lpVolumeNameBuffer="Test";//new string(;

char[] root=new char[3];

root[0]='C';

root[1]=':';

root[2]='\\';

//long *serial=&serial1;

long serial=0;

SerialReader.GetVolumeInformation(root,lpVolumeNam eBuffer,10,&serial,0,0,"FAT",10);

string result=Convert.ToString(serial);

return result;//here the result is 255 (NOT the serial).Why?

}


}

public class SerialReader

{

[DllImport("Kernel32.dll")]

unsafe public static extern bool GetVolumeInformation(

char []lpRootPathName,

string lpVolumeNameBuffer,

long nVolumeNameSize,

long *lpVolumeSerialNumber,

long lpMaximumComponentLength,

long lpFileSystemFlags,

string lpFileSystemNameBuffer,

long nFileSystemNameSize

);

}

}

//**************

I manage the GetVolumeInformation function in C++, but not in C#.

Thanks for any help.
Nov 17 '05 #1
1 4427
Remember long's are 64 bit in .NET, change them to int, when running on XP
or higher, you better use the System.Management classes and WMI's class
Win32_PhysicalMedia instead of PInvoke.

Willy.

"Arif Çimen" <ar********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi everybody
I need to get serial number of harddist drive (C:\).

Here I tried some codes.

//**************
using System;

using System.Runtime.InteropServices;

namespace HanleyUretim

{

/// <summary>

///

/// </summary>

public class ManagerClass

{

public ManagerClass()

{

//

// TODO: Add constructor logic here

//

}

//public SerialReader sr=new SerialReader();
unsafe public string GetSerial()

{

//char[]

//long serial1=0;//=(int*)new int();

string lpVolumeNameBuffer="Test";//new string(;

char[] root=new char[3];

root[0]='C';

root[1]=':';

root[2]='\\';

//long *serial=&serial1;

long serial=0;

SerialReader.GetVolumeInformation(root,lpVolumeNam eBuffer,10,&serial,0,0,"FAT",10);

string result=Convert.ToString(serial);

return result;//here the result is 255 (NOT the serial).Why?

}


}

public class SerialReader

{

[DllImport("Kernel32.dll")]

unsafe public static extern bool GetVolumeInformation(

char []lpRootPathName,

string lpVolumeNameBuffer,

long nVolumeNameSize,

long *lpVolumeSerialNumber,

long lpMaximumComponentLength,

long lpFileSystemFlags,

string lpFileSystemNameBuffer,

long nFileSystemNameSize

);

}

}

//**************

I manage the GetVolumeInformation function in C++, but not in C#.

Thanks for any help.

Nov 17 '05 #2

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

Similar topics

15
by: tom | last post by:
Hi, How do I get the serial number of the harddisk in .NET? I want this to be the same number even if the user has reformatted, so I do not want the volume serial number. Thanx, t
2
by: JanakiRaman | last post by:
Hi, Can I install visual studio .NET 2003 from harddisk? Thanks in advance, JanakiRaman S
0
by: Jonas Hei | last post by:
I need to implement a listener that listens on a certain UDP port. I am trying to use Socket.BeginReceiveFrom for this purpose. In this scenario the remote clients (hundreds of them) send most of...
6
by: angus | last post by:
Dear All, how to read the and write a file to the client's harddisk when using asp.net? is it possible to do so? Thank you. Regards,
4
by: JoskeXP | last post by:
Hi I have pictures as Jpeg file on harddisk How can I load a picture from Harddisk in a PictureBox I have the name of the picture in a textbox (databinding with a Database Th JoskeXP
6
by: mohamed azaz | last post by:
hi I want to know how can I create a simple doc file to drive D in Harddisk by using c++ code please answer me Quickly bye bye
9
rpnew
by: rpnew | last post by:
Hi All, i recently got new Compaq laptop- CQ 45-106 AU (If i'm not wrong- will update it after reaching home.). Now i have two questions regarding this. First one is i want to make partition...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.