Windows Serial Number?

Posted on 2001-06-19
Last Modified: 2010-05-02
I'm trying to find a way of getting the operating systems serial number, be it Win9x, Millenium, 2000, NT4 etc. I know I can get it from the registry, but I'd rather get it from someplace non-editable. Is this possible?
Question by:Dhag
LVL 18

Expert Comment

ID: 6207307
Option Explicit

  dwOSVersionInfoSize As Long
  dwMajorVersion As Long
  dwMinorVersion As Long
  dwBuildNumber As Long
  dwPlatformId As Long
  szCSDVersion As String * 128
End Type

Declare Function GetVersionEx Lib "kernel32.dll" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long

Public Sub versionstuff()

' Display the major and minor version numbers of Windows.
' For example, 4.0 could represent Windows 95.
Dim os As OSVERSIONINFO  ' receives version information
Dim retval As Long  ' return value

os.dwOSVersionInfoSize = Len(os)  ' set the size of the structure
retval = GetVersionEx(os)  ' read Windows's version information
Debug.Print "Windows version number:"; os.dwPlatformId, os.dwMajorVersion; "."; os.dwMinorVersion

End Sub

'some details

OSVERSIONINFO-type variables hold information about the version of Windows currently running. This structure holds various pieces of information identifying the version number, platform, and more about Windows.

The size of the structure.
The major version number; i.e., the part of the version number before the first period.
The minor version number; i.e., the part of the version number after the first period.
The build number of the version.
Exactly one of the following flags identifying which platform of Windows is running (for example, Windows 95, Windows NT, etc.):
Windows 3.x is running, using the Win32s pseudo-32-bit enhancements.
Windows 95 or 98 is running.
Windows NT is running.
More information about the operating system.
LVL 16

Expert Comment

ID: 6207474
yes, it is possible but, unfortunately, diferent version save the serial on diferent place.
You need some api stuff to read registry entries and locate some keys under \software\microsoft\windows\currentversion\productid

Accepted Solution

gbaren earned 50 total points
ID: 6207594
I don't think the serial number exists anywhere but the registry. Here's a function to get it:

You need to set a reference to Windows Script Host Object Model.

Function GetWindowsID() as string
Dim oShell As IWshShell

   Set oShell = New IWshShell_Class
   GetWindowsID = oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\ProductId")

End Function

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LVL 16

Expert Comment

ID: 6208381
Gbaren post in code what i said in simply words. Nice job.
LVL 49

Expert Comment

ID: 7139525
Hi Dhag,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Split points between: Richie_Simonetti and gbaren

Dhag, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
DanRollins -- EE database cleanup volunteer

Author Comment

ID: 7143262
I'd like to split the points between the two, but don't know how to do that :(
LVL 49

Expert Comment

ID: 7144297
Hi Dhag,
Thanks for responding.  An EE Moderator will split the points for you when she pases through here in about a week.  -- Dan

Expert Comment

ID: 7181561
Per recommendation, force-accepted.

CS Moderator

Richie_Simonetti: points for you at

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access Search and Replace Using VBA 6 83
Passing a Text Box name to a Sub 6 99
IF ELSE Statement in Excel Macro VBA 16 75
Sub or Function is not defined 6 43
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

829 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