getting hdd @cpu id or serial no

Posted on 2001-06-07
Medium Priority
Last Modified: 2006-11-17
dear frinds

i am requisting some ocx or control or windows based software or command in visual basic and the instruction of use for reading the serial no. or(id no.)of the hard disk drive (not the lable name or no.) and also to get the id no. (serial no.) of the cpu


Question by:jssjss

Expert Comment

by:Valliappan AN
ID: 6163019

Expert Comment

ID: 6163425
TRY THIS MY FRIEND. This will get you the HARD disk or any other disk's serial number, just cut and paste it in VB

ive put notes in for you to follow, just create a form with a command button and put this code in to it.



code below :=

Option Explicit

Private Declare Function GetVolumeInformation& Lib "kernel32" _
    Alias "GetVolumeInformationA" (ByVal lpRootPathName _
    As String, ByVal pVolumeNameBuffer As String, ByVal _
    nVolumeNameSize As Long, lpVolumeSerialNumber As Long, _
    lpMaximumComponentLength As Long, lpFileSystemFlags As _
    Long, ByVal lpFileSystemNameBuffer As String, ByVal _
    nFileSystemNameSize As Long)
    Const MAX_FILENAME_LEN = 256

Private Sub Command1_Click()
    Label1.Caption = SerNum("C") 'C is the standard harddisk
End Sub

Public Function SerNum(Drive$) As Long
    Dim No&, s As String * MAX_FILENAME_LEN
    Call GetVolumeInformation(Drive + ":\", s, MAX_FILENAME_LEN, _
    No, 0&, 0&, s, MAX_FILENAME_LEN)
    SerNum = No
End Function

Private Sub Form_Load()
End Sub


Expert Comment

ID: 6163429
dont put all the code in the command button sorry.

just create a command button,

well you know what to do so ill leave it with you

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 6163454
dont put all the code in the command button sorry.

just create a command button,

well you know what to do so ill leave it with you


Expert Comment

ID: 6163487
for information regarding your cpu this does the lot.

you will need to download :- http://msdn.microsoft.com/downloads/sdks/wmi/default.asp

before you run this code.



Private asCpuPaths() As String
Private m_objCPUSet As SWbemObjectSet
Private m_objWMINameSpace As SWbemServices
Option Explicit

Private Sub cmdDone_Click()
Unload Me
End Sub

Private Sub Form_Load()

Dim oCpu As SWbemObject 'WMI Object, in this case, local CPUs
Dim sPath As String, sCaption As String

Dim lElement As Long
ReDim asCpuPaths(0) As String

On Error GoTo ErrorHandler

'Get Default NameSpace, which will be the one for the local machine
Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
Set m_objWMINameSpace = GetObject("winmgmts:")

'Get CPU set

Set m_objCPUSet = m_objWMINameSpace.InstancesOf("Win32_Processor")
sCaption = m_objCPUSet.Count & " processor"
If m_objCPUSet.Count <> 1 Then sCaption = sCaption & "s"
sCaption = sCaption & " detected on this machine"
lblTitle.Caption = sCaption
'Populate list box with CPU names
For Each oCpu In m_objCPUSet
     With oCpu
        sPath = .Path_ & ""
            If sPath <> "" Then
                lstCPU.AddItem .Name
                'save path to array, so on machines with multiple CPUs,
                'each can be identified and their info loaded into text box
                lElement = IIf(asCpuPaths(0) = "", 0, UBound(asCpuPaths) + 1)
                ReDim Preserve asCpuPaths(lElement) As String
                asCpuPaths(lElement) = sPath
            End If
     End With
If lstCPU.ListCount <> 0 Then lstCPU.ListIndex = 0

Set oCpu = Nothing

Exit Sub

MsgBox "CPU Information could not be displayed due to the following error: " & Err.Description, , "WMI Demo Failed"
GoTo CleanUp
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set m_objCPUSet = Nothing
Set m_objWMINameSpace = Nothing
End Sub

Private Sub lstCPU_Click()
Dim oCpu As SWbemObject
'Refer to SDK documentation for more detail about each of these properties
Dim sInfoString As String
On Error Resume Next
Set oCpu = m_objCPUSet(asCpuPaths(lstCPU.ListIndex))
With oCpu
    sInfoString = "Description: " & .Description & vbCrLf
    sInfoString = sInfoString & "Processor ID: " & .ProcessorID & vbCrLf
    sInfoString = sInfoString & "Status: " & .Status & vbCrLf
    sInfoString = sInfoString & "Manufacturer: " & .Manufacturer & vbCrLf
    sInfoString = sInfoString & "Availability: " & AvailabilityToString(.Availability) & vbCrLf
    sInfoString = sInfoString & "Load Percentage: " & .LoadPercentage & vbCrLf
    sInfoString = sInfoString & "Current Clock Speed: " & .CurrentClockSpeed & " MHz" & vbCrLf
    sInfoString = sInfoString & "Maximum Clock Speed: " & .MaxClockSpeed & vbCrLf
    sInfoString = sInfoString & "Level 2 Cache Size: " & .L2CacheSize & vbCrLf
    sInfoString = sInfoString & "Level 2 Cache Speed: " & .L2CacheSpeed & vbCrLf
    sInfoString = sInfoString & "Power Management Supported: " & .PowerManagementSupported
End With
txtCpu.Text = sInfoString

End Sub
'Conversions from code to string were developed
'based on information in WMI SDK documentation
Private Function AvailabilityToString(Code As Integer) As String
Dim sAns As String

Select Case Code
    Case 1, 2
        sAns = "Unknown"
    Case 3
        sAns = "Running/Full Power"
    Case 4
        sAns = "Warning"
    Case 5
        sAns = "In Test"
    Case 6
        sAns = "Not Applicable"
    Case 7
        sAns = "Power Off"
    Case 8
        sAns = "Off Line"
    Case 9
        sAns = "Off Duty"
    Case 10
        sAns = "Degraded"
    Case 11
        sAns = "Not Installed"
    Case 12
        sAns = "Install Error"
    Case 13
        sAns = "Power Save - Unknown"
    Case 14
        sAns = "Power Save - Low Power Mode"
    Case 15
        sAns = "Power Save - Standby"
    Case 16
        sAns = "Power Cycle"
    Case 17
        sAns = "Power Save - Warning"
    Case Else
        sAns = "Unknown"
End Select
AvailabilityToString = sAns

End Function


good luck
hope thats what you wanted


Author Comment

ID: 6195373
the answer you giv to me is not correct with all respect

the code that you giv is only read the volum name but what i am waiting for is the hdd serial no. by manufacturer like that software dm(disk manager) but under windows

also i have additional quistion:

how i can use or create cheqbox in db grid in visual basic programing so that i can make acheq mark on items i did


Expert Comment

by:Valliappan AN
ID: 6195995
Did u try the links, that I have provided. It should return the serial number only, and not the vol. name, if I am right.

I dont think, you could create a check box in db grid. You should get some other tools, like, the one from Sheridan. Sheridan DBGrid, has options for cheque box, etc.

Or, may be, some other tools, like Apex TrueDbgrid, I have not used this. I think, they also have this.

hope this helps.


Expert Comment

by:Valliappan AN
ID: 6196001
Sorry, the one I typed,

for cheque box, etc.

should read as,

for check box, etc.
LVL 28

Accepted Solution

Ark earned 200 total points
ID: 6552956
Take a look on my samples:

>>This class allows you to get BIOS information. For NT/2000, it reads the registry for this information; for 95/98/ME, you can do it by reading the system's memory using pointers<<

>>Here is a code to get low level HDD info. Tested on w95(OSR2)/98/NT/2000. At least Primary master HDD info is available (including HDD serial number, physical geometry and miscelaneous HDD parameters).<<


Expert Comment

ID: 7017626
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
POINTS FOR EXPERTS awaiting comments are listed in the link below
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
Thanks everyone.
Moderator @ Experts Exchange
LVL 49

Expert Comment

ID: 7133393
Hi jssjss,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept Ark's comment(s) as an answer.
*** Ark's second link provides request info (low-level serial#, not 'soft' volume id)

jssjss, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
DanRollins -- EE database cleanup volunteer

Expert Comment

ID: 7167816
Comment from expert accepted as answer

E-E Moderator

Expert Comment

ID: 12571040
Dear frinds

Is there any body who has ocx or code to encrypt data stored in data base

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question