'How to get S.M.A.R.T. info from disks?

I tried code found in Google but nothing works and in most cases it doesn't even compile (missing units, undeclared data types etc). I finally found something that looks complete but shows "The handle is invalid" error: http://rsdn.org/article/delphi/SMART.xml You can download the file from here: http://rsdn.org/article/delphi/smart/smart.zip

The problem is with function function OpenSMART(DrvNum:Byte): THandle;

hSMARTIOCTL:=CreateFile(PChar('\\.\PhysicalDrive'+inttostr(DrvNum)),GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,nil,OPEN_EXISTING,0,0);
result:= hSMARTIOCTL;

How can I fix it or where can I find working example?

I use Delphi 7 Pro and Delphi 10.3.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source