Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract the key code

Status
Not open for further replies.

bertieuk

IS-IT--Management
Joined
Jun 1, 2004
Messages
175
I have written a script to extract all the info on the server hardware that we use. I need to extend this by extracting the OS CD-Key. I know it is in the registry but dosen't seem to be obvious where.

Has anyone else tried this? I can use a third party gui version but I want all the info relating to the server together and scheduled.

I have a script that will extract registry value so I'm nearly already to go.

Thanks Si
 
You can easily grab this with WMI.


More infor than you could ever ask for (the Serial Number is what you were looking for):

[script]
'==========================================================================
'
' NAME: GetOSInfo.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: ' COPYWRITE (c) 2005 All Rights Reserved
' DATE : 9/18/2005
'
' COMMENT:
'
'==========================================================================
Set WshShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
Report = Report & vbCrLf & "BootDevice: " & objItem.BootDevice
Report = Report & vbCrLf & "BuildNumber: " & objItem.BuildNumber
Report = Report & vbCrLf & "BuildType: " & objItem.BuildType
Report = Report & vbCrLf & "Caption: " & objItem.Caption
Report = Report & vbCrLf & "CodeSet: " & objItem.CodeSet
Report = Report & vbCrLf & "CountryCode: " & objItem.CountryCode
Report = Report & vbCrLf & "CreationClassName: " & objItem.CreationClassName
Report = Report & vbCrLf & "CSCreationClassName: " & objItem.CSCreationClassName
Report = Report & vbCrLf & "CSDVersion: " & objItem.CSDVersion
Report = Report & vbCrLf & "CSName: " & objItem.CSName
Report = Report & vbCrLf & "CurrentTimeZone: " & objItem.CurrentTimeZone
Report = Report & vbCrLf & "DataExecutionPrevention_32BitApplications: " & objItem.DataExecutionPrevention_32BitApplications
Report = Report & vbCrLf & "DataExecutionPrevention_Available: " & objItem.DataExecutionPrevention_Available
Report = Report & vbCrLf & "DataExecutionPrevention_Drivers: " & objItem.DataExecutionPrevention_Drivers
Report = Report & vbCrLf & "DataExecutionPrevention_SupportPolicy: " & objItem.DataExecutionPrevention_SupportPolicy
Report = Report & vbCrLf & "Debug: " & objItem.Debug
Report = Report & vbCrLf & "Description: " & objItem.Description
Report = Report & vbCrLf & "Distributed: " & objItem.Distributed
Report = Report & vbCrLf & "EncryptionLevel: " & objItem.EncryptionLevel
Report = Report & vbCrLf & "ForegroundApplicationBoost: " & objItem.ForegroundApplicationBoost
Report = Report & vbCrLf & "FreePhysicalMemory: " & objItem.FreePhysicalMemory
Report = Report & vbCrLf & "FreeSpaceInPagingFiles: " & objItem.FreeSpaceInPagingFiles
Report = Report & vbCrLf & "FreeVirtualMemory: " & objItem.FreeVirtualMemory
Report = Report & vbCrLf & "InstallDate: " & objItem.InstallDate
Report = Report & vbCrLf & "LargeSystemCache: " & objItem.LargeSystemCache
Report = Report & vbCrLf & "LastBootUpTime: " & objItem.LastBootUpTime
Report = Report & vbCrLf & "LocalDateTime: " & objItem.LocalDateTime
Report = Report & vbCrLf & "Locale: " & objItem.Locale
Report = Report & vbCrLf & "Manufacturer: " & objItem.Manufacturer
Report = Report & vbCrLf & "MaxNumberOfProcesses: " & objItem.MaxNumberOfProcesses
Report = Report & vbCrLf & "MaxProcessMemorySize: " & objItem.MaxProcessMemorySize
Report = Report & vbCrLf & "Name: " & objItem.Name
Report = Report & vbCrLf & "NumberOfLicensedUsers: " & objItem.NumberOfLicensedUsers
Report = Report & vbCrLf & "NumberOfProcesses: " & objItem.NumberOfProcesses
Report = Report & vbCrLf & "NumberOfUsers: " & objItem.NumberOfUsers
Report = Report & vbCrLf & "Organization: " & objItem.Organization
Report = Report & vbCrLf & "OSLanguage: " & objItem.OSLanguage
Report = Report & vbCrLf & "OSProductSuite: " & objItem.OSProductSuite
Report = Report & vbCrLf & "OSType: " & objItem.OSType
Report = Report & vbCrLf & "OtherTypeDescription: " & objItem.OtherTypeDescription
Report = Report & vbCrLf & "PlusProductID: " & objItem.PlusProductID
Report = Report & vbCrLf & "PlusVersionNumber: " & objItem.PlusVersionNumber
Report = Report & vbCrLf & "Primary: " & objItem.Primary
Report = Report & vbCrLf & "ProductType: " & objItem.ProductType
Report = Report & vbCrLf & "QuantumLength: " & objItem.QuantumLength
Report = Report & vbCrLf & "QuantumType: " & objItem.QuantumType
Report = Report & vbCrLf & "RegisteredUser: " & objItem.RegisteredUser
Report = Report & vbCrLf & "SerialNumber: " & objItem.SerialNumber
Report = Report & vbCrLf & "ServicePackMajorVersion: " & objItem.ServicePackMajorVersion
Report = Report & vbCrLf & "ServicePackMinorVersion: " & objItem.ServicePackMinorVersion
Report = Report & vbCrLf & "SizeStoredInPagingFiles: " & objItem.SizeStoredInPagingFiles
Report = Report & vbCrLf & "Status: " & objItem.Status
Report = Report & vbCrLf & "SuiteMask: " & objItem.SuiteMask
Report = Report & vbCrLf & "SystemDevice: " & objItem.SystemDevice
Report = Report & vbCrLf & "SystemDirectory: " & objItem.SystemDirectory
Report = Report & vbCrLf & "SystemDrive: " & objItem.SystemDrive
Report = Report & vbCrLf & "TotalSwapSpaceSize: " & objItem.TotalSwapSpaceSize
Report = Report & vbCrLf & "TotalVirtualMemorySize: " & objItem.TotalVirtualMemorySize
Report = Report & vbCrLf & "TotalVisibleMemorySize: " & objItem.TotalVisibleMemorySize
Report = Report & vbCrLf & "Version: " & objItem.Version
Report = Report & vbCrLf & "WindowsDirectory: " & objItem.WindowsDirectory
Next


Set ts = oFSO.CreateTextFile (strComputer & ".txt", ForWriting)
ts.write report
ts.close

WshShell.Run("Notepad " & strComputer & ".txt")
[/script]

I hope you find this post helpful.

Regards,

Mark
 
Mark

Thanks for the reply.

Its was actually the original CD KEY that must be entered at install that I was after extracting. This is within the machine registry but needs to be decoded.

Si
 
mrmovie
I did put the link that held the script in an earlier post....This is not my script and I cannot take the credit (as if I would), but I have further adapted it for my inventory script. The original is .....


Set WshShell = WScript.CreateObject("WScript.Shell")
strDigitalProductId="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"

strXPKey=GetKey(WshShell.RegRead(strDigitalProductId))
MsgBox "WinXP:"&strXPKey&chr(13)


Function GetKey(rpk)

Const rpkOffset=52:i=28
szPossibleChars="BCDFGHJKMPQRTVWXY2346789"

Do 'Rep1
dwAccumulator=0 : j=14
Do
dwAccumulator=dwAccumulator*256
dwAccumulator=rpk(j+rpkOffset)+dwAccumulator
rpk(j+rpkOffset)=(dwAccumulator\24) and 255
dwAccumulator=dwAccumulator Mod 24
j=j-1
Loop While j>=0
i=i-1 : szProductKey=mid(szPossibleChars,dwAccumulator+1,1
)&szProductKey
if (((29-i) Mod 6)=0) and (i<>-1) then
i=i-1 : szProductKey="-"&szProductKey
End If
Loop While i>=0 'Goto Rep1

GetKey=szProductKey
End Function


 
rr thanks for that bertieuk, nice for me to have
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top