Solved

How to retrieve some system information from VB

Posted on 2001-06-19
14
798 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…

809 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