Featured Posts

WP Comments Manager Today we are very proud to announce the release of our first Windows Phone 7 application that binds your Wordpress based blogs with your Windows Phone. Now you can manage your blog comments directly...

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

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 Windows 7. you don' t need ...

Readmore

  • Prev
  • Next

HDDPhysic Visual Basic .NET example (VS 2005)

Posted By : rlByte Team | In : HDDPhysic

0

Source code example for using HDDPhysic component to get hard disk physical info (like the unique hdd serial number) with VB.NET 2005 is now available in the resources area of the product (here).

  Here are some few steps on how you should use it in VB.NET:

(1) Declare imported library functions:
HDiskInfo.vb :

Option Strict Off
Option Explicit On
Imports System.Runtime.InteropServices


Module HDiskInfo
    Public Declare Function Init Lib "HDDPhysic.dll" (ByVal sUser As String, ByVal sRegCode As String) As Integer
    Public Declare Function GetPhysicInfo Lib "HDDPhysic.dll" (ByVal diskIndex As Short, ByVal InfoType As Integer, ByVal pHddInfo As String) As Integer
End Module

(2) Call the Init function to initialize the user computer hard drives and get the total available devices:
Form1.vb :

    Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        Dim tDiscs As Integer
        Dim intX As Short
        Dim WinHdd As Short

        tDiscs = Init("your reg code here", "your reg code here")

        If tDiscs > 0 Then
            For intX = 0 To tDiscs - 1
                Me.Combo1.Items.Add(intX) 'populate combo with hdd indexes
            Next
            WinHdd = GetPhysicInfo(0, 6, "") 'get windows hdd index
            If WinHdd >= 0 Then
                edtDrive.Text = WinHdd   'windows is installed on this drive index            
                Combo1.SelectedIndex = WinHdd
            End If
        End If

    End Sub

(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:

   Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click

        Dim iDiskNo As Integer
        Dim sBuffer As String
        Dim iReturn As Integer

        sBuffer = Space(1024) ' make room in the buffer        
        iDiskNo = Combo1.SelectedIndex 'get selected disk number
        ClearEdit() 'clear previous values

        iReturn = GetPhysicInfo(iDiskNo, 0, sBuffer) '0 = serial number        
        Text1.Text = Strings.Left(sBuffer, iReturn)

        iReturn = GetPhysicInfo(iDiskNo, 1, sBuffer) '1 = hdd model
        Text2.Text = Strings.Left(sBuffer, iReturn)

        iReturn = GetPhysicInfo(iDiskNo, 2, sBuffer) '2 = hdd revision        
        Text3.Text = Strings.Left(sBuffer, iReturn)

        iReturn = GetPhysicInfo(iDiskNo, 3, sBuffer) '3 = hdd type        
        Text7.Text = Strings.Left(sBuffer, iReturn)

        iReturn = GetPhysicInfo(iDiskNo, 4, sBuffer) '4 = hdd size        
        Text5.Text = Strings.Left(sBuffer, iReturn)

        iReturn = GetPhysicInfo(iDiskNo, 5, sBuffer) '5 = hdd buffer size
        Text4.Text = Strings.Left(sBuffer, iReturn)

    End Sub

Tags: , , , , ,


Write a comment

*