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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WMI script to find OS Product Key 2

Status
Not open for further replies.

kjohnson530

IS-IT--Management
Mar 26, 2006
28
US
Hello all,

I'm currently working on creating an asset inventory tool (as opposed to purchasing one). I'm doing so using WMI scripting and I was wonder two things:

1. is it possible to get the Operating System's Product Key from WMI.

2. If so how do I go about doing that?


Thank you in advance.

 
You'll most likely find this helpful (and once again, kudos to Mark for this excellent script):

Code:
'==========================================================================
' NAME: GetCDKeyandSerialNumber.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 3/16/2006
' (C) 2006, All Rights Reserved
'
' COMMENT:
'
'==========================================================================
Set WshShell = CreateObject("wscript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set env = WshShell.environment("Process")
strComputer = env.Item("Computername")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Const HKEY_LOCAL_MACHINE = &H80000002
Const UnInstPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
".\root\default:StdRegProv")
strDigitalProductId="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"
strXPKey=GetKey(WshShell.RegRead(strDigitalProductId))
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
    report = report &  "Original CD Key:"& strXPKey & vbCrLf
    report = report &  "SerialNumber: " & objItem.SerialNumber & vbCrLf
Next
MsgBox report
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
 
You beat me to posting my own script tfg13. [2thumbsup]

I hope you find this post helpful.

Regards,

Mark
 
Couldn't help it Mark. I know I don't have your collection of scripts yet (all 850), but the ones you do post, I have!
 
I'm just glad they are getting some use. Shoot me an email off of one of my FAQs and I can tell you about some more I have.



I hope you find this post helpful.

Regards,

Mark
 
Thank you all for your post. I must admit that I have tried most of the options you all have suggested. Presently I have been using Belarc for inventory purposes, but my org. couldn't afford to pony up the $$ for Belarc, and though I have SMS I'm not presently ready to implement it yet. So I I wanted something that I could implement with a company SQL database that would keep me from having to physically touch each machine.

Using a product called scriptomatic from MS I've been able to gather most of the information that I needed with the exception of currently installed software with product keys, and the original product key of the OS. Thank you Mark and tfg13 that was exactly what I was looking for.
 
Always happy to be of service.

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top