Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to retrieve some system information from VB

Posted on 2001-06-19
14
Medium Priority
?
855 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 800 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

971 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