Using system;
Using system. IO;
Using system. runtime. interopservices;
Using system. text;
Using Microsoft. Win32;
Namespace wjb. readorwriteiniandreg
{
/**////
/// Read the hard disk serial number of the specified drive letter
///
Public class harddiskval
{
[Dllimport ("kernel32.dll")]
Private Static extern int getvolumeinformation (
String lprootpathname,
String lpvolumenamebuffer,
Int nvolumenamesize,
Ref int lpvolumeserialnumber,
Int lpmaximumcomponentlength,
Int lpfilesystemflags,
String lpfilesystemnamebuffer,
Int nfilesystemnamesize
);
/**////
/// Obtain the hard disk serial number with the drive letter "drvid". The default value is C.
///
///
///
Public String hdval (string drvid)
{
Const int max_filename_len = 256;
Int retval = 0;
Int A = 0;
Int B = 0;
String str1 = NULL;
String str2 = NULL;
Int I = getvolumeinformation (
Drvid + @":/",
Str1,
Max_filename_len,
Ref retval,
A,
B,
Str2,
Max_filename_len
);
Return retval. tostring ();
}
Public String hdval ()
{
Const int max_filename_len = 256;
Int retval = 0;
Int A = 0;
Int B = 0;
String str1 = NULL;
String str2 = NULL;
Int I = getvolumeinformation (
"C ://",
Str1,
Max_filename_len,
Ref retval,
A,
B,
Str2,
Max_filename_len
);
Return retval. tostring ();
}
}