Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Detecting the Hard disk's Serial Number ...

225 views
Skip to first unread message

Vipul Pathak

unread,
Jan 8, 2004, 2:46:30 AM1/8/04
to
Hello To All,
I have a need of finding a Harddisk's Serial Number (Not Partition,
GetVolumeInfo( ) is not useful).
Can some some one provide Information about this ....?

How to Gather the Serial Number of Physical Disk Drive, that is Encoded by
the Hard disk Manufacturer ?

Thanks.


--
------------------------------
V I P U L P A T H A K
eBot Technosoft Limited,
Indore, (MP), India.
http://www.ebotsoft.com


Mark Roddy

unread,
Jan 8, 2004, 7:32:32 AM1/8/04
to
On Thu, 8 Jan 2004 13:16:30 +0530, "Vipul Pathak"
<vip...@ebotsoft.com> wrote:

>Hello To All,
>I have a need of finding a Harddisk's Serial Number (Not Partition,
>GetVolumeInfo( ) is not useful).
>Can some some one provide Information about this ....?
>
>How to Gather the Serial Number of Physical Disk Drive, that is Encoded by
>the Hard disk Manufacturer ?
>
>Thanks.

Use IOCTL_STORAGE_QUERY_PROPERTY StorageDeviceIdProperty for XP or
later. For W2K use scsi passthrough to send an inquiry for mode pages
80 and 83.

=====================
Mark Roddy
Windows .NET/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

Yura

unread,
Jan 8, 2004, 12:46:05 PM1/8/04
to
Hello, Vipul.

You wrote:

VP> I have a need of finding a Harddisk's Serial Number (Not Partition,
VP> GetVolumeInfo( ) is not useful).
VP> Can some some one provide Information about this ....?

VP> How to Gather the Serial Number of Physical Disk Drive, that is Encoded by
VP> the Hard disk Manufacturer ?

MSDN's SmartApp sample does what you need
http://support.microsoft.com/download/support/mslfiles/SmartApp.exe

--
Best regars,
Yura Matyashev
Programmer of AlarIT Driver Development Depatment

Roger Wellington-Oguri

unread,
Jan 8, 2004, 1:01:24 PM1/8/04
to
If the manufacturer has actually put it there, you should be able to get it
by sending the device an ATA IDENTIFY DEVICE command. To do this, you can
open a handle to the drive and call DeviceIoControl() with the
IOCTL_SCSI_PASS_THROUGH_DIRECT command.

Roger
rog...@sbcglobal.net


"Vipul Pathak" <vip...@ebotsoft.com> wrote in message
news:%23RvD1rb...@TK2MSFTNGP12.phx.gbl...

Gary G. Little

unread,
Jan 8, 2004, 6:01:33 PM1/8/04
to
Wrong ... only if there is a SCSI-miniport that maps SCSI pass through
commands to ATA TFRs, and generally with most adapter driver combinations
that does not happen. Also, ATA pass through does not work either in 2K or
XP. XP SP2 Beta does support ATA passthrough and so does Server 2003.

--
Gary G. Little
Seagate Technologies, LLC

"Roger Wellington-Oguri" <rog...@sbcglobal.net> wrote in message
news:UVgLb.8315$SL7....@newssvr25.news.prodigy.com...

lallous

unread,
Jan 9, 2004, 2:41:56 AM1/9/04
to
Is that what you're looking for:

http://www.winsim.com/diskid32/diskid32.html

--
Elias


"Vipul Pathak" <vip...@ebotsoft.com> wrote in message

news:#RvD1rb1...@TK2MSFTNGP12.phx.gbl...

Vipul Pathak

unread,
Jan 9, 2004, 3:18:48 AM1/9/04
to
Hello Mark,

I am new to this stuff, as I am first time attempting to Access a device.
Based on your Suggestion, I wrote the following Code ....
[Code]

// This is "Trial_Ioct_Storage_Query.cpp"

#include "Windows.H"
#include "Assert.H"
// #undef _NTDDSTOR_H_
#include "NtDdStor.H"


int main()
{
HANDLE hDevice = 0 ;
STORAGE_PROPERTY_QUERY sStorageInfo /*= {0}*/ ;
LPVOID lpOutput = NULL ;
DWORD dwSizeOfOutputBuffer = 0, dwSizeReturned = 0 ;
STORAGE_DEVICE_DESCRIPTOR *lpDeviceOutput = NULL ;

hDevice = CreateFile("\\\\.\\PHYSICALDRIVE0", 0, FILE_SHARE_READ, NULL
/*SD*/,
OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, NULL) ;
assert(hDevice != NULL) ;

sStorageInfo.QueryType = PropertyStandardQuery ;
sStorageInfo.PropertyId = StorageDeviceProperty ;
dwSizeOfOutputBuffer = sizeof(STORAGE_DEVICE_HEADER) +
sizeof(STORAGE_DEVICE_DESCRIPTOR) ;
lpOutput = new BYTE[dwSizeOfOutputBuffer] ;
assert(lpOutput != NULL) ;

lpDeviceOutput = reinterpret_cast<STORAGE_DEVICE_DESCRIPTOR
*>(reinterpret_cast<LPSTR>(lpOutput) + sizeof(STORAGE_DEVICE_HEADER)) ;
DeviceIoControl(hDevice, IOCTL_STORAGE_QUERY_PROPERTY, &sStorageInfo,
sizeof(sStorageInfo), lpOutput, dwSizeOfOutputBuffer, &dwSizeReturned, NULL)
;

CloseHandle(hDevice) ;
return 0 ;
}

[/Code]

This Code doesn't Compile and return 13 Errors. It says it doesn't found any
of the Data types (eg. : STORAGE_DEVICE_DESCRIPTOR ... )
I have opened the File "NtDdStor.H" which contain the declarations of the
above Structures and Enum. But still it doesn't compiles ...
Can you please Help ?

Regards.

------------------------------
V I P U L P A T H A K
eBot Technosoft Limited,
Indore, (MP), India.
http://www.ebotsoft.com

Mark Roddy

unread,
Jan 9, 2004, 7:44:01 AM1/9/04
to
On Fri, 9 Jan 2004 13:48:48 +0530, "Vipul Pathak"
<vip...@ebotsoft.com> wrote:

>Hello Mark,
>
>I am new to this stuff, as I am first time attempting to Access a device.
>Based on your Suggestion, I wrote the following Code ....
>[Code]
>
>// This is "Trial_Ioct_Storage_Query.cpp"
>

>#include "Windows.H"
>#include "Assert.H"
>// #undef _NTDDSTOR_H_
>#include "NtDdStor.H"

Generally "it doesn't compile, what could be wrong" is not an
appropriate question for this newsgroup. I was not going to bother to
look at your code, but I did notice the above nonsense. What could be
wrong with those first four lines? Anything jump out as odd and
inappropriate? Here is a clue: the problem is between lines 2 and 4.

Gary G. Little

unread,
Jan 9, 2004, 9:08:05 AM1/9/04
to
Normally Mark you would be correct. However, storage interfaces such as pass
through, are basically broken interfaces, and require IOCTLs that may even
require an application to be compiled with storage and IOCTL definition
header files that are only found in the DDK.

In writing a DLL to enumerate ATA drives and do IDENTIFY using the ATA
Pass-through hotfix for XP, we have had to do some fancy footwork to get the
proper compiler switches turned on and off to allow sections of header code
to compile. Here is an extract from a header file that we used to allow a
proprietary API to enumerate all disks on a system:

// Windows Header Files:

#include <windows.h>

#include <winnt.h>

// BUG: The fun starts here. The non-DDK version of winioctl.h includes

// a definition of a few structures from ntddstor.h (from the DDK),

// so it wrappers them with defines to set up _NTDDSTOR_H_ around them.

//

// The problem is that if you WANT ntddstor.h for your project (for

// example, you're using a structure they haven't moved into the .NET

// version), you need to abort this behavior. You CAN'T just include

// ntddstor.h first, because it requires stuff from windows.h like DWORD.

//

// So, I "force" on the conditional flag first, so that winioctl.h won't

// try to put in its abbreviated copy, and then go back and undefine it

// so we can include the DDK version and make things right.

#define _NTDDSTOR_H_

#include <winioctl.h>

#undef _NTDDSTOR_H_

// BUG: So, now that we've gone to the trouble to ensure that we don't have

// anything from ntddstor.h created, but we can if we want to, we go

// back and grab those definitions here.

#include <ntddstor.h> // in precompiled header

//

// The fun ends here: back to your regularly scheduled program.

It tain't elegant, but its the only way we could find to get the interfaces
we needed in the application.


--
Gary G. Little
Seagate Technologies, LLC

"Mark Roddy" <mro...@nospam.spamt> wrote in message
news:fb8tvvgdvd30l9r21...@4ax.com...

http://www.schornsteintechnik24.de

unread,
Jan 9, 2004, 6:20:45 PM1/9/04
to
Hi,

I've written a VxD driver for Windows 9x, if you need it, I'll send you with the
sources & sample apps (ASM and samples in C and Pascal) . It's freeware, take
about 400 KB and due to this size I dont't want to post it in the NG, but I'm happy
to share it, if you need it. Principally I read the s/n from the hdd's BIOS in the VxD
and from C/C++ or Pascal query the VxD. Under Windows 200 /XP/.NET you're
unable to use this VxD. Sorry :-(((

Have a very nice week-end,

Robi
Schornsteintechnik in Edelstahl Frank Hlava,
http://www.schornsteintechnik24.de

.MODEL MEDIUM
.CODE

PUBLIC GetDiscInfo

;---------------------------------------------------------------
;----- Params : Nr_Disc: WORD; Buffer: DWORD pointer ----------
;---------------------------------------------------------------
GetDiscInfo PROC NEAR
PUSH BP
MOV BP,SP
PUSH ES

@1: MOV DX,1F7H
IN AL,DX
CMP AL,50H
JE @1

MOV AL,0A0H
MOV BX,[BP+8]
CMP BX,0
JE @2
MOV AL,0B0H

@2: MOV DX,1F6H
OUT DX,AL

MOV DX,1F7H
MOV AL,0ECH
OUT DX,AL

@3: IN AL,DX
CMP AL,058H
JE @3

MOV AX,0E07H
INT 10H

MOV DX,1F0H
MOV AX,[BP+6]
MOV ES,AX
MOV DI,[BP+4]
MOV CX,256

@4:
IN AX,DX
STOSW
LOOP @4

POP ES
POP BP
RET 6
GetDiscInfo ENDP
;--------------------------------------------------
END

Schornsteintechnik in Edelstahl Frank Hlava,
http://www.schornsteintechnik24.de


"Vipul Pathak" <vip...@ebotsoft.com> schrieb im Newsbeitrag news:#RvD1rb1...@TK2MSFTNGP12.phx.gbl...

0 new messages