Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
SQL Server

How to get the Windows Xp Key using VB.Net

Author: DevASP
Download Source Code : 406_Win XP

This article is about how you can get the key of your windows XP installed on you computer. In this article we will come to know how to access a registry value.

  • Steps you will do. 
  • Start visual studio and create a new window application. 
  • Set the following properties of the form.


Text = “Window’s XP Key”


Drop a label control on the form and set its following properties.


Name = “lblmsg”

Text = “”

Now drop a button control on the form and set its following properties.


Name = “btnget”

Text = ”Get the Key”


Open your code window and imports the following namespace.

Imports Microsoft.Win32


Make a function which will get the key as below.


Public Function GetXPKey() As String

Dim RegKey As RegistryKey = _

Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion", False)

Dim bytDPID() As Byte = RegKey.GetValue("DigitalProductID")

Dim bytKey(14) As Byte

Array.Copy(bytDPID, 52, bytKey, 0, 15)

Dim strChar As String = "BCDFGHJKMPQRTVWXY2346789"

Dim strKey As String = ""

For j As Integer = 0 To 24

Dim nCur As Short = 0

For i As Integer = 14 To 0 Step -1

nCur = CShort(nCur * 256 Xor bytKey(i))

bytKey(i) = CByte(Int(nCur / 24))

nCur = CShort(nCur Mod 24)


strKey = strChar.Substring(nCur, 1) & strKey


For i As Integer = 4 To 1 Step -1

strKey = strKey.Insert(i * 5, "-")


Return strKey

End Function

Now call the function in the click event of the button.

lblmsg.Text = GetXPKey()

Add Article Comment:
Name :
Email Address :
Comments :
<< Custom Exceptions & Global Exception Handlers in VB.Net

Disclaimer - Privacy
© 2002-2017