#212674 - 2017-09-12 11:46 PM
Convert WMIC code to WMI/Kix
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4545
Loc: USA
|
Having trouble converting this to usable code by kix.
wmic path SoftwareLicensingService get OA3xOriginalProductKey
The above works as expected, but using the code below returns nothing, nor does a similar vbscript.
$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
? @serror
$colItems = $objWMIService.ExecQuery("Select * from SoftwareLicensingService",,48)
? @serror
For each $objItem in $colItems
? $ObjItem.OA3xOriginalProductKey
Next
? 'Press Any Key to close the window'
get $
Am I doing something stupid? Suggestions? Thanks.
|
Top
|
|
|
|
#212677 - 2017-09-13 12:22 AM
Re: Convert WMIC code to WMI/Kix
[Re: Allen]
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4545
Loc: USA
|
My PC returns nothing. Not sure if that means my PC is activated differently or if there is something else going on. The other PC I tried, now works. Maybe I didn't test the final code, posted above, on it.
Okay. Thanks for checking it.
|
Top
|
|
|
|
#212679 - 2017-09-13 03:44 PM
Re: Convert WMIC code to WMI/Kix
[Re: Arend_]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
|
I also converted/wrote a script to retrieve the installed ProductKey to match it with the OEM key. This works most of the time. If the retrieved key is VK7JG-NPHTM-C97JM-9MPGT-3V66T then the Windows 10 installation was either upgraded from a previous OS version or the OA3 key allows the OEM machine that originally had a OEM (OA2) marker in the BIOS for Windows 7 or 8 to be used for Windows 10. So in that case you'll find a OA3 key using your code, but the Activation process changed it into the above mentioned key.
Anyway, the retrieval code for installed license only works for Windows 8 and above (8, 8.1 and 10) because MS changed the way to retrieve the code from Windows Vista and 7.
$=SetOption("wow64alternateregview","on")
$reg = ReadValue("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion","DigitalProductId")
Dim $arrKey[]
$i=1
While ($i < LEN($reg))
ReDim Preserve $arrKey[Ubound($arrKey)+1]
$arrKey[Ubound($arrKey)] = Val("&"+SubStr($reg,$i,2))
$i=$i+2
Loop
? "Installed Key: "+ConvertToKey($arrKey)
Function ConvertToKey($Key)
;Check if OS is Windows 8
$isWin8 = ($Key[66] / 6) And 1
$Key[66] = ($Key[66] And &F7) Or (($isWin8 And 2) * 4)
$KeyOffset = 52
$i = 24
$Maps = "BCDFGHJKMPQRTVWXY2346789"
Do
$Current = 0
$j = 14
Do
$Current = $Current * 256
$Current = $Key[$j+$KeyOffset] + $Current
$Key[$j + $KeyOffset] = ($Current / 24)
$Current = $Current Mod 24
$j=$j-1
Until $j < 0
$i = $i-1
$KeyOutput = SubStr($Maps, $Current+1, 1) + $KeyOutput
$Last = $Current
Until $i < 0
$keypart1 = SubStr($KeyOutput, 2, $Last)
$insert = "N"
$KeyOutput = SubStr($KeyOutput, 2, LEN($KeyOutput))
$KeyOutput = Join(Split($KeyOutput, $keypart1),$keypart1+$insert)
If $Last = 0
$KeyOutput = $insert+$KeyOutput
EndIf
$ConvertToKey=SubStr($KeyOutput,1,5)+"-"+SubStr($KeyOutput,6,5)+"-"+SubStr($KeyOutput,11,5)+"-"+SubStr($KeyOutput,16,5)+"-"+SubStr($KeyOutput,21,5)
EndFunction
|
Top
|
|
|
|
#212920 - 2017-11-21 10:58 AM
Re: Convert WMIC code to WMI/Kix
[Re: Arend_]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
|
Just for fun, here's a single line of code to retrieve the OA3 key:
$strComputer = "."
? "OA3xOriginalProductKey = "+GetObject("winmgmts:\\"+$strComputer+"\root\cimv2").ExecQuery("Select * from SoftwareLicensingService").ItemIndex(0).OA3xOriginalProductKey
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
2 registered
(morganw, mole)
and 414 anonymous users online.
|
|
|