Solved

How to retrieve some system information from VB

Posted on 2001-06-19
14
812 Views
Last Modified: 2010-05-02
Hi

I need to retrieve info through my vb application from the machine which it is installed on. Something like a CPU serial number or Motherboard serial number, or any UNIQUE number on that machine for registration purposes.

Can anyone assist me in this regard?

Thanks
0
Comment
Question by:netraLINK
  • 5
  • 5
  • 4
14 Comments
 
LVL 5

Expert Comment

by:AndrewDev
ID: 6205873
This code will get you the serial number of the hard disk drive. That should do it for you

Option Explicit

Private Declare Function GetVolumeInformation Lib _
   "kernel32.dll" Alias "GetVolumeInformationA" _
   (ByVal lpRootPathName As String, _
   ByVal lpVolumeNameBuffer As String, _
   ByVal nVolumeNameSize As Integer, _
   lpVolumeSerialNumber As Long, _
   lpMaximumComponentLength As Long, _
   lpFileSystemFlags As Long, _
   ByVal lpFileSystemNameBuffer As String, _
   ByVal nFileSystemNameSize As Long) As Long

Public Function DriveSerialNumber(ByVal Drive As String) As Long
   
    'usage: SN = DriveSerialNumber("C:\")
 
    Dim lAns As Long
    Dim lRet As Long
    Dim sVolumeName As String, sDriveType As String
    Dim sDrive As String

    'Deal with one and two character input values
    sDrive = Drive
    If Len(sDrive) = 1 Then
        sDrive = sDrive & ":\"
    ElseIf Len(sDrive) = 2 And Right(sDrive, 1) = ":" Then
        sDrive = sDrive & "\"
    End If
 
    sVolumeName = String$(255, Chr$(0))
    sDriveType = String$(255, Chr$(0))
   
    lRet = GetVolumeInformation(sDrive, sVolumeName, _
    255, lAns, 0, 0, sDriveType, 255)

DriveSerialNumber = lAns
End Function

Regards
Andrew
0
 
LVL 5

Accepted Solution

by:
AndrewDev earned 200 total points
ID: 6205879
Or if you prefer the motherboards serial number

Public Function MBSerialNumber() As String

'RETRIEVES SERIAL NUMBER OF MOTHERBOARD
'IF THERE IS MORE THAN ONE MOTHERBOARD, THE SERIAL
'NUMBERS WILL BE DELIMITED BY COMMAS

'YOU MUST HAVE WMI INSTALLED AND A REFERENCE TO
'Microsoft WMI Scripting Library IS REQUIRED

Dim objs As Object

Dim obj As Object
Dim WMI As Object
Dim sAns As String


Set WMI = GetObject("WinMgmts:")
Set objs = WMI.InstancesOf("Win32_BaseBoard")
For Each obj In objs
  sAns = sAns & obj.SerialNumber
 If sAns < objs.Count Then sAns = sAns & ","
Next
MBSerialNumber = sAns
End Function
0
 

Expert Comment

by:sachin_nigam
ID: 6205883
You can retrieve the MotherBoard's Serial Number provided you have the MS WMI library installed :-)
check out
http://www.freevbcode.com/ShowCode.asp?ID=2664&NoBox=True

..
cheers
..
Sachin
0
Technology Partners: 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!

 
LVL 5

Expert Comment

by:AndrewDev
ID: 6205886
This gets drive information using the File System Object

http://www.freevbcode.com/ShowCode.Asp?ID=1516
0
 

Expert Comment

by:sachin_nigam
ID: 6205888
You can retrieve the MotherBoard's Serial Number provided you have the MS WMI library installed :-)
check out
http://www.freevbcode.com/ShowCode.asp?ID=2664&NoBox=True

..
cheers
..
Sachin
0
 
LVL 5

Expert Comment

by:AndrewDev
ID: 6205889
sachin_nigam
Beat you to it :-)
0
 

Expert Comment

by:sachin_nigam
ID: 6205893
AndrewDev:-
is it so ;-)
0
 

Author Comment

by:netraLINK
ID: 6205918
Sheesh! What a quick response...lemme test these samples and ill award thge points accordingly...
0
 

Author Comment

by:netraLINK
ID: 6205929
Thanks guys

Gonna accept answer from AndrewDev. Only reason, he was first and he actually pasted the code for me.

Thanks again
0
 

Author Comment

by:netraLINK
ID: 6205936
There ya go!
0
 

Expert Comment

by:sachin_nigam
ID: 6205942
well i feel if code is not yours then you should always acknowledge it..isn't it?? :-X
anywez...
Sachin
0
 

Author Comment

by:netraLINK
ID: 6205948
You are right sachin...

Thanks for your help anyways...
0
 
LVL 5

Expert Comment

by:AndrewDev
ID: 6206526
Thanks netraLINK

>>well i feel if code is not yours then you should always acknowledge it
Ooops - I usually do, mine was the same link that sachin_nigam posted just after me. The code was so short I thought it was of more use to post the code, forgot to say where it was from.

Hence my beat you to it comment

Happy coding :-)
Andrew
 
0
 

Author Comment

by:netraLINK
ID: 6206576
Ok Guys - stop fighting over this one - hehehehe.

Rather go and see - I posted another 200 point question...

C u there!
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

735 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