Solved

How to retrieve some system information from VB

Posted on 2001-06-19
14
783 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
This gets drive information using the File System Object

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

Expert Comment

by:sachin_nigam
Comment Utility
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
Comment Utility
sachin_nigam
Beat you to it :-)
0
 

Expert Comment

by:sachin_nigam
Comment Utility
AndrewDev:-
is it so ;-)
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

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

Author Comment

by:netraLINK
Comment Utility
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
Comment Utility
There ya go!
0
 

Expert Comment

by:sachin_nigam
Comment Utility
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
Comment Utility
You are right sachin...

Thanks for your help anyways...
0
 
LVL 5

Expert Comment

by:AndrewDev
Comment Utility
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
Comment Utility
Ok Guys - stop fighting over this one - hehehehe.

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

C u there!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now