Rick
Fri Dec 17 10:27:30 CST 2004
Thanks Leonid,
I'll try to convert this code to VFP and let you know if it works.
Rick
"Leonid" <leonid@NOgradaSPAM.lv> wrote in message =
news:%23p5xxHD5EHA.2428@TK2MSFTNGP14.phx.gbl...
> Rick,
>=20
> If you are interesed in serial number for SCSI drives, I found next =
code on=20
> Russian web. Of course it's not written in foxpro. I can't verify it =
because=20
> I haven't SCSI drives on my XP.
>=20
>=20
> program ScsiSN;
>=20
> // PURPOSE: Simple console application that display SCSI harddisk =
serial=20
> number
>=20
> {$APPTYPE CONSOLE}
>=20
> uses
> Windows, SysUtils;
>=20
> //-------------------------------------------------------------=20
> function GetDeviceHandle( sDeviceName : String ) : THandle;
> begin
> Result :=3D CreateFile( PChar('\\.\'+sDeviceName),
> GENERIC_READ or GENERIC_WRITE,
> FILE_SHARE_READ or FILE_SHARE_WRITE,
> nil, OPEN_EXISTING, 0, 0 )
> end;
>=20
> //-------------------------------------------------------------=20
> function ScsiHddSerialNumber( DeviceHandle : THandle ) : String;
> {$ALIGN ON}
> type
> TScsiPassThrough =3D record
> Length : Word;
> ScsiStatus : Byte;
> PathId : Byte;
> TargetId : Byte;
> Lun : Byte;
> CdbLength : Byte;
> SenseInfoLength : Byte;
> DataIn : Byte;
> DataTransferLength : ULONG;
> TimeOutValue : ULONG;
> DataBufferOffset : DWORD;
> SenseInfoOffset : ULONG;
> Cdb : Array[0..15] of Byte;
> end;
> TScsiPassThroughWithBuffers =3D record
> spt : TScsiPassThrough;
> bSenseBuf : Array[0..31] of Byte;
> bDataBuf : Array[0..191] of Byte;
> end;
> {ALIGN OFF}
> var dwReturned : DWORD;
> len : DWORD;
> Buffer : Array[ 0..SizeOf(TScsiPassThroughWithBuffers)+
> SizeOf(TScsiPassThrough)-1] of Byte;
> sptwb : TScsiPassThroughWithBuffers absolute Buffer;
> begin
> Result :=3D '';
> FillChar(Buffer,SizeOf(Buffer),#0);
> with sptwb.spt do
> begin
> Length :=3D SizeOf(TScsiPassThrough);
> CdbLength :=3D 6; // CDB6GENERIC_LENGTH
> SenseInfoLength :=3D 24;
> DataIn :=3D 1; // SCSI_IOCTL_DATA_IN
> DataTransferLength :=3D 192;
> TimeOutValue :=3D 2;
> DataBufferOffset :=3D PChar(@sptwb.bDataBuf)-PChar(@sptwb);
> SenseInfoOffset :=3D PChar(@sptwb.bSenseBuf)-PChar(@sptwb);
> Cdb[0] :=3D $12; // OperationCode :=3D SCSIOP_INQUIRY;
> Cdb[1] :=3D $01; // Flags :=3D CDB_INQUIRY_EVPD; Vital product =
data
> Cdb[2] :=3D $80; // PageCode Unit serial number
> Cdb[4] :=3D 192; // AllocationLength
> end;
> len :=3D sptwb.spt.DataBufferOffset+sptwb.spt.DataTransferLength;
> if DeviceIoControl( DeviceHandle, $0004d004, @sptwb,=20
> SizeOf(TScsiPassThrough), @sptwb, len, dwReturned, nil )
> and ((PChar(@sptwb.bDataBuf)+1)^=3D#$80)
> then
> SetString( Result, PChar(@sptwb.bDataBuf)+4,
> Ord((PChar(@sptwb.bDataBuf)+3)^) );
> end;
>=20
>=20
> =
//=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> var
> hDevice : THandle =3D 0;
> sSerNum, sDeviceName : String;
>=20
> begin
> sDeviceName :=3D ParamStr(1);
> if sDeviceName=3D'' then
> begin
> WriteLn;
> WriteLn('Display SCSI-2 device serial number.');
> WriteLn;
> WriteLn('Using:');
> WriteLn;
> if Win32Platform=3DVER_PLATFORM_WIN32_NT then // Windows NT/2000
> WriteLn(' ScsiSN PhysicalDrive0')
> else
> WriteLn(' ScsiSN C:');
> WriteLn(' ScsiSN Cdrom0');
> WriteLn(' ScsiSN Tape0');
> WriteLn;
> Exit;
> end;
> hDevice :=3D GetDeviceHandle(sDeviceName);
> if hDevice=3DINVALID_HANDLE_VALUE then
> WriteLn('Error on GetDeviceHandle: ',SysErrorMessage(GetLastError))
> else
> try
> sSerNum :=3D ScsiHddSerialNumber(hDevice);
> if sSerNum=3D'' then
> WriteLn('Error on DeviceIoControl: ',
> SysErrorMessageGetLastError))
> else
> WriteLn('Device '+sDeviceName
> +' serial number =3D "',sSerNum,'"');
> finally
> CloseHandle(hDevice);
> end;
> end.
>=20
> // For more information about SCSI commands:
> // ftp://ftp.t10.org/t10/drafts/scsi-1/
> // ftp://ftp.t10.org/t10/drafts/spc/
> // ftp://ftp.t10.org/t10/drafts/spc2/
>=20
>=20
> Leonid
>=20
>=20
> "Rick Bean" <rgbean@unrealmelange-inc.com> wrote in message=20
> news:eczogR34EHA.2804@TK2MSFTNGP15.phx.gbl...
> Leonid,
> Yup, Lynn McGuire's comment "written with many contributions from =
others,=20
> IDE drives only under Windows NT/2K and 9X, maybe SCSI drives later" =
says it=20
> all.
>=20
> Rick
>=20
> "Leonid" <leonid@NOgradaSPAM.lv> wrote in message=20
> news:O6nrM%23z4EHA.2624@TK2MSFTNGP11.phx.gbl...
>> Hi, Rick
>>
>> I beleive it works only on IDE HDDs, I didn't verify it on SCSI. You =
may
>> check
>>
>>
http://www.winsim.com/diskid32/diskid32.cpp
>>
>> Leonid
>>
>> "Rick Bean" <rgbean@unrealmelange-inc.com> wrote in message
>> news:%23sFHZsu4EHA.3380@TK2MSFTNGP09.phx.gbl...
>> Leonid,
>> I've got three SCSI HDDs partioned into 3, 2, 1 drives respectively, =
and
>> none of the six returned a value for Serial, although it did return =
six
>> different VolSNs. Are there any known limitations to your routine?
>>
>> Rick
>>
>> "Leonid" <leonid@NOgradaSPAM.lv> wrote in message
>> news:es3OHmt2EHA.1076@TK2MSFTNGP09.phx.gbl...
>>> To get not only logical, but also physical drive information you may =
try:
>>>
>>>
>>> * You must have local administrative rights
>>>
>>> Declare Integer CloseHandle in kernel32 Integer hObject
>>> Declare Integer CreateFile in kernel32 String lpFileName, ;
>>> Integer dwDesiredAccess, Integer dwShareMode, ;
>>> Integer lpSecurityAttributes, Integer dwCreationDisposition, ;
>>> Integer dwFlagsAndAttributes, Integer hTemplateFile
>>>
>>> Declare Integer DeviceIoControl in kernel32 Integer hDevice, ;
>>> Integer dwIoControlCode, String @lpInBuffer, ;
>>> Long nInBufferSize, String @lpOutBuffer, ;
>>> Long nOutBufferSize, Integer @lpBytesReturned, ;
>>> Integer lpOverlapped
>>>
>>> Declare Integer GetLogicalDriveStrings in Win32API ;
>>> Integer buflen, String @buf
>>> Declare Integer GetDriveType in Win32API String m.path
>>> Declare Integer GetVolumeInformation in Win32API ;
>>> String lpRootPathName, String @lpVolumeNameBuffer, ;
>>> Integer nVolumeNameSize, Long @lpVolumeSerialNumber, ;
>>> Integer @lpMaximumComponentLength, Integer @lpFileSystemFlags, ;
>>> String @lpFileSystemNameBuffer, Integer nFileSystemNameSize
>>>
>>> clear
>>> m.buflen=3D104
>>> m.buf=3Dreplicate(chr(0),m.buflen)
>>> GetLogicalDriveStrings(m.buflen, @m.buf)
>>> m.buf=3Dchrtran(m.buf,chr(0)+"\:","")
>>> m.str1=3D""
>>> for m.i=3D1 to len(m.buf)
>>> m.drvtype=3DGetDriveType(substr(m.buf,m.i,1)+":\")
>>> if m.drvtype=3D3
>>> m.str1=3Dm.str1+substr(m.buf,m.i,1)
>>> endif
>>> next
>>>
>>> for m.i=3D1 to len(m.str1)
>>> m.vnb=3Dreplicate(chr(0),64)
>>> m.vnbs=3D64
>>> m.vsn=3D0
>>> m.mcl=3D0
>>> m.fsf=3D0
>>> m.fsnb=3Dreplicate(chr(0),10)
>>> m.fsnbs=3D10
>>>
>>> GetVolumeInformation(substr(m.str1,m.i,1)+":\", ;
>>> @m.vnb,m.vnbs,@m.vsn,@m.mcl,@m.fsf,@m.fsnb,m.fsnbs)
>>>
>>> if m.vsn<0
>>> m.vsn=3Dm.vsn+16^8
>>> endif
>>> m.vsn=3Dpadl(allt(substr(Transform(m.vsn,"@0"),3)),8,"0")
>>>
>>> m.drivenumber=3Dasc(substr(m.str1,m.i,1))-asc("C")
>>> handle =3D CreateFile("\\.\"+chr(asc("c")+m.drivenumber)+":", ;
>>> 0xC0000000, 3, 0, 3, 0, 0)
>>>
>>> m.sn=3D""
>>> m.mod=3D""
>>> m.rev=3D""
>>> if handle<>-1
>>> m.sci=3D""
>>> m.sci=3Dm.sci+chr(0)+chr(2)+chr(0)+chr(0)
>>> m.sci=3Dm.sci+chr(0)
>>> m.sci=3Dm.sci+chr(1)
>>> m.sci=3Dm.sci+chr(1)
>>> m.sci=3Dm.sci+chr(0)
>>> m.sci=3Dm.sci+chr(0)
>>> m.sci=3Dm.sci+chr(0xA0)
>>> m.sci=3Dm.sci+chr(0xEC)
>>> m.sci=3Dm.sci+chr(0)
>>> m.sci=3Dm.sci+chr(0)
>>> m.sci=3Dm.sci+repl(chr(0),499)
>>>
>>> m.sco=3Dreplicate(chr(0),2048)
>>> m.ret_buffersize=3D0
>>> m.otv=3DDeviceIoControl(handle, 0x7C088, @m.sci, len(sci), ;
>>> @m.sco, len(sco), @m.ret_buffersize, 0)
>>>
>>> CloseHandle(handle)
>>> if m.otv<>0
>>> m.sn=3Dchrtran(allt(conv21(substr(m.sco,37,20))),chr(0),"")
>>> m.rev=3Dchrtran(allt(conv21(substr(m.sco,63,8))),chr(0),"")
>>> m.mod=3Dchrtran(allt(conv21(substr(m.sco,71,40))),chr(0),"")
>>> endif
>>> endif
>>>
>>> ?substr(m.str1,m.i,1)+":\ VolSN: "+m.vsn+" "+ ;
>>> chrtran(m.fsnb,chr(0),"")+" Model: "+m.mod+ ;
>>> " Revision: "+m.rev+" Serial: "+m.sn
>>> next
>>>
>>>
>>> function conv21
>>> lparameter m.str
>>> if len(m.str)%2=3D1
>>> m.str=3Dm.str+" "
>>> endif
>>> local m.i, m.str2
>>> m.str2=3D""
>>> for m.i=3D1 to len(m.str)
>>> m.str2=3Dm.str2+substr(m.str,m.i+iif(m.i%2=3D0,-1,1),1)
>>> next
>>> return m.str2
>>>
>>> Leonid
>>>
>>>
>>> <tnhoe@pc.jaring.my> wrote in message =
news:41b1af7d_2@news.tm.net.my...
>>>> Hi,
>>>>
>>>> How do I get the harddisk serial number from VFP program which =
using XP
>>>> professional ?
>>>>
>>>> Regards
>>>> Hoe
>>>>
>>>
>>>
>>
>>=20
>=20
>