Featured Posts

Using IssProc with NSIS to detect files in use Although IssProc was specially designed for Inno Setup scripts, you can also use it with other setup scripts like NSIS (Nullsoft Scriptable Install System) :) Here is a few steps you need to do in...

Readmore

Using IssProc with NSIS to detect files in use Although IssProc was specially designed for Inno Setup scripts, you can also use it with other setup scripts like NSIS (Nullsoft Scriptable Install System) Here is a few steps you need to do in order...

Readmore

IssProc (DLL Component) Launched IssProc is a user friendly "file in use" extension for Inno Setup (or other setup builder application like NSIS) that can be used to detect if a certain application (exe, dll module, ocx and so on) or...

Readmore

HDDPhysic v1.1.0 is released! Today we've released a new updated version of HDDPhysic (v1.1.0) Here is what’s new in this version: improved hardware serial extraction in Vista and W blog book guest levitra ru siteindows...

Readmore

Promote software on your website and get paid for it!... Join our affiliates network and get 25% commission on every sale you refer! Become a rlByte Software affiliate today!   To start selling, all you need to do is display product information...

Readmore

  • Prev
  • Next

USBPhysic C# example (source code sample)

Posted on : 09-02-2010 | By : rlByte Team | In : USBPhysic, rlByte News

2

 In order to get the usb storage device (external portable Hard Drives, flash/pen/key drive etc) serial number and other manufacturer information (NOT volume serial, only the unique one, the one that will not change after a format, physical one) using our USBPhysic library and C# (CSharp) you need to do the following 3 easy steps:

(1) Load USBPhysic library and declare the imported library functions :

 namespace USBPhysic_Example
{
    public partial class Form1 : Form
    {
        //load the library
        [DllImport("USBPhysic")]
        public static extern int Init(string sUser, string sRegCode);

        [DllImport("USBPhysic")]
        public static extern int GetUSBPhysicInfo(int diskIndex, int InfoType, StringBuilder pHddInfo);

        public Form1()
        {
            InitializeComponent();
        }

(2) Call the Init function to initialize the user computer usb storage devices

       private void Form1_Load(object sender, EventArgs e)
        {
            int USBDisks = Init("your reg code here", "your reg code here");

            if (USBDisks > 0)
            {
                for (int i = 0; i < USBDisks; i++)
                {
                    comboBox1.Items.Add(i);
                }
                comboBox1.SelectedIndex = 0;
            }
        }

(3) Now that you have the total hard drives count you can query for the manufacturer information passing the usb device index to the GetPhysicInfo function:

       private void button1_Click(object sender, EventArgs e)
        {
            const int nChars = 1024;
            StringBuilder Buff = new StringBuilder(nChars);
           
            //0 = Get SerialNumber
            if (GetUSBPhysicInfo(Int32.Parse(comboBox1.Items[comboBox1.SelectedIndex].ToString()), 0, Buff) > 0)
                textBox1.Text = Buff.ToString();
            else
                textBox1.Text = "n/a";

            //1 = Get product name
            if (GetUSBPhysicInfo(Int32.Parse(comboBox1.Items[comboBox1.SelectedIndex].ToString()), 1, Buff) > 0)
                textBox2.Text = Buff.ToString();
            else
                textBox2.Text = "n/a";

            //2 = Get USB Manufacturer
            if (GetUSBPhysicInfo(Int32.Parse(comboBox1.Items[comboBox1.SelectedIndex].ToString()), 2, Buff) > 0)
                textBox3.Text = Buff.ToString();
            else
                textBox3.Text = "n/a";

            //3 = Get drive letter mapped on Windows
            if (GetUSBPhysicInfo(Int32.Parse(comboBox1.Items[comboBox1.SelectedIndex].ToString()), 3, Buff) > 0)
                textBox4.Text = Buff.ToString();
            else
                textBox4.Text = "n/a";
           
        }

screenshot

  A complete project with source code example for using USBPhysic component to get usb device (hard disk, storage device pen etc) physical information with CSharp (C#) is available in the resources area of the product (here).

Hdd Physic Delphi Example (with source)

Posted on : 18-11-2009 | By : rlByte Team | In : HDDPhysic

0

 In order to get the hard disk serial number and other manufacturer information (NOT volume serial, only the unique one, the one that will not change after a format, physical one) using our hddphysic product and delphi code you need to do the following 3 easy steps:

(1) Create a new unit called HDDPhysic where you declare the imported hddphysic library functions :

HddPhysic.pas :

unit HddPhysic;

interface

  function Init (sUser: PAnsiChar; sRegCode: PAnsiChar): Integer; stdcall; external 'HDDPhysic.dll';
  function GetPhysicInfo (idiskIndex: Integer; iInfoType: Integer;  pHddInfo_OUT: PAnsiChar): Integer; stdcall; external 'HDDPhysic.dll';

implementation

end.

(2) Include the HddPhysic.pas in your project and then Call the Init function to initialize the user computer hard drives and get the total available devices

procedure TForm1.FormCreate(Sender: TObject);
var
 iWinDrive, iDrivesCount, i: Integer;
begin
   i:=0;
   //init HddPhysic dll
   iDrivesCount:=Init('<your reg id>','<your reg code>'); //add your registration data to unlock it

  if iDrivesCount>0 then
   begin
      //add drives indexes to combo
     Repeat
        ComboBoxDrives.Items.Add(IntToStr(i));
        Inc(i);
     Until i = iDrivesCount ;
      //get windows hdd drive index
      iWinDrive     := GetPhysicInfo(0, 6, nil);
      WinDrive.Text := IntToStr(iWinDrive);
      ComboBoxDrives.ItemIndex := iWinDrive ; //select windows drive index
   end;
end;

(3) Now that you have the total hard drives count you can query for the manufacturer information passing the disk index to the GetPhysicInfo function:

procedure TForm1.Button1Click(Sender: TObject);
var
  iDiskNo,iReturn: Integer;
  cInfo: AnsiString;
begin
  SetLength( cInfo, 512 ); //allocate some space in the buffer
  ClearEdit;
 
  iDiskNo:=ComboBoxDrives.ItemIndex; //get selected drive index
 
  iReturn    := GetPhysicInfo(iDiskNo,0,PAnsiChar(cInfo)); //0 = hdd serial number
  Edit1.Text := cInfo;                

  iReturn    := GetPhysicInfo(iDiskNo, 1, PAnsiChar(cInfo));    //1 = hdd model
  Edit2.Text := cInfo;
   
  iReturn    := GetPhysicInfo(iDiskNo, 2, PAnsiChar(cInfo));    //2 = hdd revision
  Edit3.Text := cInfo;

  iReturn    := GetPhysicInfo(iDiskNo, 3, PAnsiChar(cInfo));    //3 = hdd type
  Edit6.Text := cInfo;
       
  iReturn    := GetPhysicInfo(iDiskNo, 4, PAnsiChar(cInfo));    //4 = hdd size
  Edit5.Text := cInfo;
   
  iReturn    := GetPhysicInfo(iDiskNo, 5, PAnsiChar(cInfo));    //5 = hdd buffer size
  Edit4.Text := cInfo;

end;

Notes: No errors checks are done in this example, you should do some

error checks.

For example the Init function returns zero if no hdd are found, and GetPhysicInfo returns a lower than zero value

if it fails for some reason.

  A complete project with source code example for using HDDPhysic component to get hard disk physical information with Delphi (CodeGear Delphi 2009) is available in the resources area of the product (here).