Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 04-16-2014, 02:05 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,060
Default Hard drive physical number.

Hi,

I have some code which return the hard drive physical/ manufacture number which use for the last three years. But recently this code does no work with some new types of hard drives. So my question. Anybody know a good component that can work with all types of hard drives? I am not looking for free ones.
__________________
Regards,
Abdulaziz Jasser

Last edited by Jasser; 05-19-2014 at 01:53 PM.
Reply With Quote
  #2  
Old 04-16-2014, 07:16 PM
kolbasz kolbasz is offline
Senior Member
 
Join Date: Nov 2013
Posts: 841
Default

Jesser I'm just curious, did you get the HDD info through windows management instrumentation? This should work with the newer HDD's.

Code:
uses ActiveX, ComObj;

var
  FSWbemLocator: OLEVariant;
  FWMIService: OLEVariant;


function GetWMIString(const WMIClass, WMIProperty: String): String;
const
  wbemFlagForwardOnly = $00000020;
var
  FWbemObjectSet: OLEVariant;
  FWbemObject: OLEVariant;
  oEnum: IEnumvariant;
  iValue: LongWord;
begin;
  Result := '';
  FWbemObjectSet:= FWMIService.ExecQuery(Format('Select %s from %s', [WMIProperty, WMIClass]), 'WQL',wbemFlagForwardOnly);
  oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
  if oEnum.Next(1, FWbemObject, iValue) = 0 then
   if not VarIsNull(FWbemObject.Properties_.Item(WMIProperty).Value) then
     Result := FWbemObject.Properties_.Item(WMIProperty).Value;
  FWbemObject := Unassigned;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  x: String;
begin
  FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  FWMIService := FSWbemLocator.ConnectServer('localhost', 'root\CIMV2', '', '');
  X := GetWMIString('Win32_PhysicalMedia', 'SerialNumber');
  ShowMessage(x);
end;
Reply With Quote
  #3  
Old 04-20-2014, 06:18 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,060
Default

Thanks kolbasz. I will test the code on different hard drives and get back to you.
__________________
Regards,
Abdulaziz Jasser
Reply With Quote
  #4  
Old 04-23-2014, 05:56 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,060
Default

It works like a dream...thanks.
__________________
Regards,
Abdulaziz Jasser
Reply With Quote
  #5  
Old 04-23-2014, 07:26 AM
kolbasz kolbasz is offline
Senior Member
 
Join Date: Nov 2013
Posts: 841
Default

You're welcome Jasser!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 01:25 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.