Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to retrieve some system information from VB

Posted on 2001-06-19
14
Medium Priority
?
846 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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

661 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