Page 1 of 8

retrieve harddisk`s modell,serial,firmware (Windows only)

Posted: Tue Jun 17, 2003 10:31 am
by Rings

Code: Select all

Structure IDEREGS
    bFeaturesReg.b
    bSectorCountReg.b
    bSectorNumberReg.b
    bCylLowReg.b
    bCylHighReg.b
    bDriveHeadReg.b
    bCommandReg.b
    bReserved.b
EndStructure
Structure SENDCMDINPARAMS
    cBufferSize.l
    irDriveRegs.IDEREGS
    bDriveNumber.b
    bReserved.b(3)
    dwReserved.l(4)
EndStructure

Structure  DRIVERSTATUS
    bDriveError.b
    bIDEStatus.b
    bReserved.b(2)
    dwReserved.l(2)
EndStructure
Structure  SENDCMDOUTPARAMS
    cBufferSize.l
    DStatus.DRIVERSTATUS     
    bBuffer.b(512) 
EndStructure


#DFP_RECEIVE_DRIVE_DATA = $7C088

bin.SENDCMDINPARAMS
bout.SENDCMDOUTPARAMS



Procedure.s ChangeHighLowByte(Instring.s)
;Change BIG-Little Endian
sdummy.s=""
L=Len(Instring)
For I=1 To L Step 2
 If (I+1)<=L
  sdummy.s=sdummy.s + Mid(Instring,I+1,1)+Mid(Instring,I,1)  
 EndIf
Next I 
ProcedureReturn sdummy.s
EndProcedure 


mvarCurrentDrive=0 ;If you have more hard-disks change it here

hdh = CreateFile_("\\.\PhysicalDrive" + Str(mvarCurrentDrive),#GENERIC_READ | #GENERIC_WRITE, #FILE_SHARE_READ | #FILE_SHARE_WRITE,0, #OPEN_EXISTING, 0, 0)
If hdh  
        bin\bDriveNumber = mvarCurrentDrive
        bin\cBufferSize = 512
        
        If (mvarCurrentDrive & 1) 
          bin\irDriveRegs\bDriveHeadReg = $B0
        Else
          bin\irDriveRegs\bDriveHeadReg = $A0
        EndIf
        bin\irDriveRegs\bCommandReg = $EC
        bin\irDriveRegs\bSectorCountReg = 1
        bin\irDriveRegs\bSectorNumberReg = 1
    
       br=0
       Result=DeviceIoControl_( hdh, #DFP_RECEIVE_DRIVE_DATA, bin, SizeOf(SENDCMDINPARAMS), bout, SizeOf(SENDCMDOUTPARAMS), @br, 0)
       If br>0
        hddfr = 55:hddln = 40          :
        Modell.s=ChangeHighLowByte(PeekS(@bout\bBuffer[0]+hddfr-1 ,hddln  ) )
        hddfr = 21:hddln = 20          :
        Serial.s=Trim(ChangeHighLowByte(PeekS(@bout\bBuffer[0]+hddfr-1 ,hddln  ) ))
        hddfr = 47:hddln = 8          
        Firmware.s=ChangeHighLowByte(PeekS(@bout\bBuffer[0]+hddfr-1 ,hddln  ) )
        MessageRequester("Info about your harddisk","vendor(Modell)="+Modell.s + Chr(13) +"serial="+Serial.s+ Chr(13)+"Firmwareversion="+Firmware ,0)
       EndIf
Else
  beep_(100,100)
endif 

Re: retrieve harddisk`s modell,serial,firmware (Windows only

Posted: Tue Jun 17, 2003 7:03 pm
by ricardo
Dosen't work in w98 :(

Re: retrieve harddisk`s modell,serial,firmware (Windows only

Posted: Tue Jun 17, 2003 7:14 pm
by Rings
ricardo wrote:Dosen't work in w98 :(
yes, i use

Code: Select all

\\.\PhysicalDrive"
which is not present under win89.
I'm sorry but i cannot supported win89.

Re: retrieve harddisk`s modell,serial,firmware (Windows only

Posted: Tue Jun 17, 2003 7:22 pm
by ricardo
But then why i can'r make it run there?


Rings wrote: which is not present under win89.
I'm sorry but i cannot supported win89.
??? I don't understand

Posted: Tue Jun 17, 2003 7:32 pm
by Revolver
Windows 95/98/ME doesn't allow that kind of access to the drives. Thats why in my dll users with those platforms need to copy the .vxd file to the system folder. Its a virtual device driver that allows the dll to talk to the ide drives. Windows NT/2000/XP doesn't need to do this. Also, I believe that you have to have administrator rights in NT/2000/XP for Ring's code to work. With my dll, you can have any user access.

Re: retrieve harddisk`s modell,serial,firmware (Windows only

Posted: Wed Jun 18, 2003 5:37 am
by Max.
ricardo wrote:But then why i can'r make it run there???? I don't understand
Ricardo,

I cannot try it at the moment, but from what I read on MSDN
http://support.microsoft.com/default.as ... bContent=1,
you need to change the CreateFile call to

Code: Select all

hdh=CreateFile("\\\\.\\SMARTVSD", 0,0,0,                      #CREATE_NEW, 0, 0)
and check the further requirements:

SMARTVSD Troubleshooting Checklist
If opening SMARTVSD fails in Window 95 or Windows 98, one of the following might be the cause:


You are using the original version of Windows 95, which does not support SMART (the SDI_506.PDR port driver does not contain IDE PASSTHROUGH functionality).
SMARTVSD.VXD is not installed in the \windows\system\iosubsys directory.
You did not restart after installing SMARTVSD.VXD.
Your filesystem is running in Compatibility Mode (see the System Properties dialog box, click the Performance tab). This means that the protected mode IOS subsystem, containing SMARTVSD, is being bypassed.
Your system does not have any IDE drives. ESDI_506.PDR does not remain resident if there are no IDE drives.
Your IDE drives are using a third-party SCSI miniport driver instead of Microsoft's ESDI_506 driver.
Windows 98 inadvertently omitted SMARTVSD
Hope it helps a bit...

Garbage error??!

Posted: Wed Aug 27, 2003 7:18 pm
by Seldon
I've tried to compile it with PB3.72, but I get a "Garbage at the end of file" error in lines 15. 16,22,23 and 28. What's wrong with arrays inside a structure??? Thank you.

Re: Garbage error??!

Posted: Wed Aug 27, 2003 7:28 pm
by Max.
Seldon wrote:I've tried to compile it with PB3.72, but I get a "Garbage at the end of file" error in lines 15. 16,22,23 and 28. What's wrong with arrays inside a structure??? Thank you.
Seldon,

change the lines like this

Old:
bReserved.b(3)

New:
bReserved.b[3]

using square brackets instead of parenthesises for any array inside structures.

Posted: Thu Aug 28, 2003 1:51 pm
by Rings
that point with those different brackets is anoying !!!never have this problems under VB or Powerbasic.......time to fix that!

Posted: Tue Oct 07, 2003 11:29 pm
by Seldon
Hi alls and thanks for reply. Using the routine, I noticed that this line:

Code: Select all

If hdh
should be changed into:

Code: Select all

If hdh<>#INVALID_HANDLE_VALUE   
Also, here it is the code I did for easy Win9x/NT+ compatibility (simply add such lines before the others) :

Code: Select all


#VER_PLATFORM_WIN32_WINDOWS=1
VersionInfo.OSVERSIONINFO
 
VersionInfo\dwOSVersionInfoSize = SizeOf(OSVERSIONINFO)
res=GetVersionEx_(VersionInfo)
If res
 If VersionInfo\dwPlatformId=#VER_PLATFORM_WIN32_WINDOWS

  hdh=CreateFile_("\\.\SMARTVSD",#GENERIC_READ|#GENERIC_WRITE,#FILE_SHARE_READ|#FILE_SHARE_WRITE,0,#OPEN_EXISTING,0,0)

 Else

  hdh=CreateFile_("\\.\PhysicalDrive"+Str(ndrive),#GENERIC_READ|#GENERIC_WRITE,#FILE_SHARE_READ|#FILE_SHARE_WRITE,0,#OPEN_EXISTING,0,0)  

 EndIf
EndIf

Remember to move the Smartvsd.vxd file in Windows\System\IOSUBSYS under Windows98 to make it work.

Posted: Wed Oct 08, 2003 2:15 pm
by TerryHough
Thanks for the tip Seldon, but I get nothing with Win98SE and I do have
SMARTVSD.VXD in the correct place.

If you have working code for Win98SE I would certainly like to see it.

Thanks,
Terry

Posted: Wed Oct 08, 2003 2:40 pm
by dmoc
Terry, check the size of SMARTVSD.VXD. It didn't work for me at first because I have a Promise IDE Controller that put it's own version in place of MS's. I found the original in Windows\System and (after backing-up the Promise version) put this in Windows\System\IOSubsys and it worked fine.

I think the MS one is 18K, the Promise one 9K but look at the file properties to be sure.

Posted: Wed Oct 08, 2003 2:55 pm
by TerryHough
Thanks Dmoc. I do have the correct one in \Windows\System\Iosybsys.

Must be something in the code I have tried to cobble together from this
post.

???
Terry

Posted: Wed Oct 08, 2003 3:02 pm
by dmoc
Here's my edited code:

Code: Select all

Structure IDEREGS 
  bFeaturesReg.b 
  bSectorCountReg.b 
  bSectorNumberReg.b 
  bCylLowReg.b 
  bCylHighReg.b 
  bDriveHeadReg.b 
  bCommandReg.b 
  bReserved.b 
EndStructure 

Structure SENDCMDINPARAMS 
  cBufferSize.l 
  irDriveRegs.IDEREGS 
  bDriveNumber.b 
  bReserved.b[3] 
  dwReserved.l[4] 
EndStructure 

Structure  DRIVERSTATUS 
  bDriveError.b 
  bIDEStatus.b 
  bReserved.b[2] 
  dwReserved.l[2] 
EndStructure 
Structure  SENDCMDOUTPARAMS 
  cBufferSize.l 
  DStatus.DRIVERSTATUS
  bBuffer.b[512] 
EndStructure 

#DFP_RECEIVE_DRIVE_DATA = $7C088 

bin.SENDCMDINPARAMS 
bout.SENDCMDOUTPARAMS 

Procedure.s ChangeHighLowByte(Instring.s) 
  ;Change BIG-Little Endian 
  sdummy.s="" 
  L=Len(Instring) 
  For I=1 To L Step 2 
    If (I+1)<=L 
      sdummy.s=sdummy.s + Mid(Instring,I+1,1)+Mid(Instring,I,1)  
    EndIf 
  Next I 
  ProcedureReturn sdummy.s 
EndProcedure 


mvarCurrentDrive=0 ;If you have more hard-disks change it here 

;hdh = CreateFile_("\\.\PhysicalDrive" + Str(mvarCurrentDrive),#GENERIC_READ | #GENERIC_WRITE, #FILE_SHARE_READ | #FILE_SHARE_WRITE,0, #OPEN_EXISTING, 0, 0) 
;hdh = CreateFile_("\\.\SMARTVSD" + Str(mvarCurrentDrive),#GENERIC_READ | #GENERIC_WRITE, #FILE_SHARE_READ | #FILE_SHARE_WRITE,0, #OPEN_EXISTING, 0, 0) 
;hdh = CreateFile_("\\.\SMARTVSD", 0,0,0, #CREATE_NEW, 0, 0)
;If hdh

#VER_PLATFORM_WIN32_WINDOWS = 1 
VersionInfo.OSVERSIONINFO 

VersionInfo\dwOSVersionInfoSize = SizeOf(OSVERSIONINFO) 
res=GetVersionEx_(VersionInfo) 
If res 
  If VersionInfo\dwPlatformId=#VER_PLATFORM_WIN32_WINDOWS 
    hdh=CreateFile_("\\.\SMARTVSD",#GENERIC_READ|#GENERIC_WRITE,#FILE_SHARE_READ|#FILE_SHARE_WRITE,0,#OPEN_EXISTING,0,0) 
  Else 
    hdh=CreateFile_("\\.\PhysicalDrive"+Str(ndrive),#GENERIC_READ|#GENERIC_WRITE,#FILE_SHARE_READ|#FILE_SHARE_WRITE,0,#OPEN_EXISTING,0,0) 
  EndIf 
EndIf 

If hdh<>#INVALID_HANDLE_VALUE 
  bin\bDriveNumber = mvarCurrentDrive 
  bin\cBufferSize = 512 
  
  If (mvarCurrentDrive & 1) 
    bin\irDriveRegs\bDriveHeadReg = $B0 
  Else 
    bin\irDriveRegs\bDriveHeadReg = $A0 
  EndIf 
  bin\irDriveRegs\bCommandReg = $EC 
  bin\irDriveRegs\bSectorCountReg = 1 
  bin\irDriveRegs\bSectorNumberReg = 1 
  
  br=0 
  Result=DeviceIoControl_( hdh, #DFP_RECEIVE_DRIVE_DATA, bin, SizeOf(SENDCMDINPARAMS), bout, SizeOf(SENDCMDOUTPARAMS), @br, 0) 
  If br>0 
    hddfr = 55:hddln = 40: Modell.s=ChangeHighLowByte(PeekS(@bout\bBuffer[0]+hddfr-1 ,hddln  ) ) 
    hddfr = 21:hddln = 20: Serial.s=Trim(ChangeHighLowByte(PeekS(@bout\bBuffer[0]+hddfr-1 ,hddln  ) )) 
    hddfr = 47:hddln = 8 : Firmware.s=ChangeHighLowByte(PeekS(@bout\bBuffer[0]+hddfr-1 ,hddln  ) ) 
    MessageRequester("Info about your harddisk","vendor(Modell)="+Modell.s + Chr(13) +"serial="+Serial.s+ Chr(13)+"Firmwareversion="+Firmware ,0) 
  EndIf 
Else 
  Debug "ERROR: Could not open media!"
  beep_(100,100) 
EndIf 

End

PS: This line...

Code: Select all

    hdh=CreateFile_("\\.\SMARTVSD",#GENERIC_READ|#GENERIC_WRITE,#FILE_SHARE_READ|#FILE_SHARE_WRITE,0,#OPEN_EXISTING,0,0) 
...for safety I would change to...

Code: Select all

    hdh=CreateFile_("\\.\SMARTVSD",#GENERIC_READ,#FILE_SHARE_READ,0,#OPEN_EXISTING,0,0) 

Posted: Wed Oct 08, 2003 4:09 pm
by TerryHough
Thanks dmoc. That works for me. Now I will go see where I messed up.

Terry