Jump to content

Get XP, (PLUS?), Product Key


OldCoder
 Share

Recommended Posts

I found a Visual BASIC code for extracting installed Microsoft products, (including Operating Systems), key from the registry. After hours of conversion, this is what I came up with:

$a=RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductId")
If $a<>"" Then
    $xpkey=MSDecode($a, "-")
    ClipPut($xpkey)
    InputBox("Windows OS Product Key", "The installed Windows Operating System Product Key has been copied to the clipboard and is:", $xpkey)
Else
    MsgBox(0,"ERROR","No Product Key Found")
EndIf


;   Decodes The XP Key In The Registry

; *(May work for other installed Microsoft Products)

Func MSDecode($msd_prodid, $msd_sep="")

$msd_decoded =""
$msd_code="BCDFGHJKMPQRTVWXY2346789"
Dim $msd_encoded[16]
$msd_cnt=0
For $msd_t = 105 To 135 Step + 2
    $msd_encoded[$msd_cnt]=Dec(StringMid($msd_prodid, $msd_t, 2))
    $msd_cnt += 1
Next
$msd_cnt=1
For $msd_t = 29 To 1 Step - 1
If $msd_cnt <> 6 Then
    $msd_mod = 0
    For $msd_r = 14 To 0 Step -1
        $msd_bit = BitOR(BitShift($msd_mod, -8), $msd_encoded[$msd_r])
        $msd_encoded[$msd_r] = Int($msd_bit / 24)
        $msd_mod = Mod($msd_bit, 24)
    Next
    $msd_decoded = StringMid($msd_code, $msd_mod + 1, 1) & $msd_decoded
    $msd_cnt += 1
Else
    $msd_cnt=1
    If $msd_sep<>"" Then $msd_decoded = $msd_sep & $msd_decoded
EndIf
Next
Return $msd_decoded

EndFunc

Perhaps with some minor adjustments you could use this to extract your installed MS Office key or other MS Products. Not sure if this works on any other operating system, but it might. I wanted to add this to a setup.exe replacement in an unattended XP install I was creating.

Hope this is found useful to someone. Cheers.

:mellow:

"Intelligence is the ability to adapt to change."                                      - Stephen Hawking                                        "...not the ability to exploit others."                                                  - OldCoder
Link to comment
Share on other sites

  • Replies 44
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Nice. Here is for your office key:

Msgbox(0, "", getofficekey())
; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1 beta
; Author:         Thorsten Meger 
;
; Script Function:Get & decode OfficeKey
; ----------------------------------------------------------------------------
Dim $Bin = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductID")
Func getOfficeKey()
    Local $List[1]
    Local $i = 1
    $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Common\InstallRoot", "Path")
    If $var <> "" Then
        $product = "2003"
        Dim $officeKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Registration"
    Else
        $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0\Common\InstallRoot", "Path")
        If @error <> 0 Then
            ConsoleWrite("Info: Unable to find installationPath")
            Return "No Office XP or 2003 found"
        EndIf
        If $var <> "" Then
            $product = "XP"
            Dim $officeKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0\Registration"
        EndIf
    EndIf
    Dim $var = RegEnumKey($officeKey, $i)
    If @error <> 0 Then
        ConsoleWrite("Info: Unable to find REG_BINARY 'DigitalProductID', maybe no Office installed!")
        Return "No Office XP or 2003 found"
    Else
        $List[$i - 1] = RegRead($officeKey & "\" & $var, "DigitalProductID")
        If $List[$i - 1] = "" Then
            ConsoleWrite("Info: Unable to find REG_BINARY 'DigitalProductID', maybe no Office installed!")
        Else
            $Key = $List[$i - 1]
            Return DecodeProductKey($Key)
        EndIf
    EndIf
EndFunc   ;==>getOfficeKey
; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1 beta
; Author:         Unknown & Thorsten Meger <Thorsten.Meger@gmx.de>
;
; Script Function: Decode REG_BINARY
; ----------------------------------------------------------------------------

Func DecodeProductKey($BinaryDPID)
    Local $bKey[15]
    Local $sKey[29]
    Local $Digits[24]
    Local $Value = 0
    Local $hi = 0
    Local $n = 0
    Local $i = 0
    Local $dlen = 29
    Local $slen = 15
    Local $Result
    
    $Digits = StringSplit("BCDFGHJKMPQRTVWXY2346789", "")
    $BinaryDPID = StringMid($BinaryDPID, 105, 30)
    For $i = 1 To 29 Step 2
        $bKey[Int($i / 2) ] = Dec(StringMid($BinaryDPID, $i, 2))
    Next
    For $i = $dlen - 1 To 0 Step - 1
        If Mod(($i + 1), 6) = 0 Then
            $sKey[$i] = "-"
        Else
            $hi = 0
            For $n = $slen - 1 To 0 Step - 1
                $Value = BitOR(BitShift($hi, -8), $bKey[$n])
                $bKey[$n] = Int($Value / 24)
                $hi = Mod($Value, 24)
            Next
            $sKey[$i] = $Digits[$hi + 1]
        EndIf
    Next
    For $i = 0 To 28
        $Result = $Result & $sKey[$i]
    Next
    Return $Result
EndFunc   ;==>DecodeProductKey
Edited by Melba23
Removed email address

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

Nice. Here is for your office key:

Msgbox(0, "", getofficekey())
; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1 beta
; Author:         Thorsten Meger 
;
; Script Function:Get & decode OfficeKey
; ----------------------------------------------------------------------------
Dim $Bin = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductID")
Func getOfficeKey()
    Local $List[1]
    Local $i = 1
    $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Common\InstallRoot", "Path")
    If $var <> "" Then
        $product = "2003"
        Dim $officeKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Registration"
    Else
        $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0\Common\InstallRoot", "Path")
        If @error <> 0 Then
            ConsoleWrite("Info: Unable to find installationPath")
            Return "No Office XP or 2003 found"
        EndIf
        If $var <> "" Then
            $product = "XP"
            Dim $officeKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0\Registration"
        EndIf
    EndIf
    Dim $var = RegEnumKey($officeKey, $i)
    If @error <> 0 Then
        ConsoleWrite("Info: Unable to find REG_BINARY 'DigitalProductID', maybe no Office installed!")
        Return "No Office XP or 2003 found"
    Else
        $List[$i - 1] = RegRead($officeKey & "\" & $var, "DigitalProductID")
        If $List[$i - 1] = "" Then
            ConsoleWrite("Info: Unable to find REG_BINARY 'DigitalProductID', maybe no Office installed!")
        Else
            $Key = $List[$i - 1]
            Return DecodeProductKey($Key)
        EndIf
    EndIf
EndFunc   ;==>getOfficeKey
; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1 beta
; Author:         Unknown & Thorsten Meger <Thorsten.Meger@gmx.de>
;
; Script Function: Decode REG_BINARY
; ----------------------------------------------------------------------------

Func DecodeProductKey($BinaryDPID)
    Local $bKey[15]
    Local $sKey[29]
    Local $Digits[24]
    Local $Value = 0
    Local $hi = 0
    Local $n = 0
    Local $i = 0
    Local $dlen = 29
    Local $slen = 15
    Local $Result
    
    $Digits = StringSplit("BCDFGHJKMPQRTVWXY2346789", "")
    $BinaryDPID = StringMid($BinaryDPID, 105, 30)
    For $i = 1 To 29 Step 2
        $bKey[Int($i / 2) ] = Dec(StringMid($BinaryDPID, $i, 2))
    Next
    For $i = $dlen - 1 To 0 Step - 1
        If Mod(($i + 1), 6) = 0 Then
            $sKey[$i] = "-"
        Else
            $hi = 0
            For $n = $slen - 1 To 0 Step - 1
                $Value = BitOR(BitShift($hi, -8), $bKey[$n])
                $bKey[$n] = Int($Value / 24)
                $hi = Mod($Value, 24)
            Next
            $sKey[$i] = $Digits[$hi + 1]
        EndIf
    Next
    For $i = 0 To 28
        $Result = $Result & $sKey[$i]
    Next
    Return $Result
EndFunc   ;==>DecodeProductKey
doesn't work for Office 2007 - "No Office XP or 2003" Edited by Melba23
Removed email address
Link to comment
Share on other sites

I did this one a year ago with AutoIt version 3.2.6.0 and is very similar to Nirsoft.

ProductKey.exe Source code below.

ProductKey.au3

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=.\Icons\MainGui.ico
#AutoIt3Wrapper_Allow_Decompile=n
#AutoIt3Wrapper_Res_Description=Microsoft License Key
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Copyright © 2007 - Danny35d
#AutoIt3Wrapper_Res_Language=1033
://////=__=
#AutoIt3Wrapper_Res_Icon_Add=F:\Scripts\Windows_Keys\Icons\EditCopy.ico
#AutoIt3Wrapper_Res_Icon_Add=F:\Scripts\Windows_Keys\Icons\EditSelect.ico
#AutoIt3Wrapper_Res_Icon_Add=F:\Scripts\Windows_Keys\Icons\EditDeselect.ico
#AutoIt3Wrapper_Res_Icon_Add=F:\Scripts\Windows_Keys\Icons\FileExit.ico
#AutoIt3Wrapper_Res_Icon_Add=F:\Scripts\Windows_Keys\Icons\FileSave.ico
#AutoIt3Wrapper_Res_Icon_Add=F:\Scripts\Windows_Keys\Icons\HelpAbout.ico
#AutoIt3Wrapper_Res_Icon_Add=F:\Scripts\Windows_Keys\Icons\ListView.ico
#AutoIt3Wrapper_Res_Icon_Add=F:\Scripts\Windows_Keys\Icons\ViewHtmlSelect.ico
#AutoIt3Wrapper_Res_Icon_Add=F:\Scripts\Windows_Keys\Icons\ViewRefresh.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

;** Target program Resource info

#include <Array.au3>
#include <.\Include\WAP_UDF.au3>
#include <GUIConstants.au3>
#include <.\Include\ModernMenuLib.au3>
#Include <GuiListView.au3>
#Include <GuiStatusBar.au3>



Opt('GUIOnEventMode', 1)

Global $Title = 'Microsoft License Key'
;Global $RGBColors[2] = [0x778899, 0x6495ed]
Global $RGBColors[2] = [0xffffff, 0xd4d4d4]
Global $ChangeStatus = False, $TotalItems, $RemoteComputer, $LastRemoteComputer = @ComputerName
Global $SwitchColor = 0
Local $a_PartsRightEdge[1] = [-1]
Local $a_PartsText[1] = ['']

$MainGUI = GUICreate($Title, 578, 245, -1, -1)
$MenuFile = GUICtrlCreateMenu("File")
    $MenuFileSave = _GUICtrlCreateODMenuItem("Save Selected Items   Ctrl+S", $MenuFile, @ScriptFullPath, 7)
    _GUICtrlCreateODMenuItem("", $MenuFile) ; Separator
    $MenuFileExit = _GUICtrlCreateODMenuItem("Exit", $MenuFile, @ScriptFullPath, 6)
$MenuEdit = GUICtrlCreateMenu("Edit")
    $MenuEditCopy = _GUICtrlCreateODMenuItem("Copy Selected Items   Ctrl+C", $MenuEdit, @ScriptFullPath, 3)
    _GUICtrlCreateODMenuItem("", $MenuEdit) ; Separator
    $MenuEditSelect = _GUICtrlCreateODMenuItem("Select All                      Ctrl+A", $MenuEdit, @ScriptFullPath, 4)
    $MenuEditDeselect = _GUICtrlCreateODMenuItem("Deselect All                  Ctrl+D", $MenuEdit, @ScriptFullPath, 5)
$MenuView = GUICtrlCreateMenu("View")
    $MenuViewRefresh = _GUICtrlCreateODMenuItem("Refresh F5", $MenuView, @ScriptFullPath, 11)
    $MenuViewReportAll = _GUICtrlCreateODMenuItem("HTML Report - All Items", $MenuView, @ScriptFullPath, 10)
    $MenuViewSelectedItems = _GUICtrlCreateODMenuItem("HTML Report - Selected Items", $MenuView, @ScriptFullPath, 10)
$MenuHelp = GUICtrlCreateMenu("Help")
    $MenuHelpAbout = _GUICtrlCreateODMenuItem("About", $MenuHelp, @ScriptFullPath, 8)
$ListView = GUICtrlCreateListView("Product Name|Product ID|Product Key|Computer Name", 8, 8, 562, 150, _
    $LVS_SHOWSELALWAYS, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUICtrlSetBkColor(-1, $RGBColors[0])

$Label = GUICtrlCreateLabel("Remote Computer", 8, 170, 89, 17)
$RemoteInp = GUICtrlCreateInput("", 104, 168, 153, 21)
$RefreshBtn = GUICtrlCreateButton("Refresh", 264, 170, 59, 17, 0)
$CloseBtn = GUICtrlCreateButton("Close", 496, 168, 75, 25, 0)
$StatusBar = _GUICtrlStatusBarCreate ($MainGUI, $a_PartsRightEdge, $a_PartsText)
_GuiOnEvent()
GUISetState(@SW_SHOW)
_EnableHotKeys()
_AddItemsToListView(_GetWindowsKey())
_AddItemsToListView(_GetOfficeKey())

While 1
    Sleep(50)
    If _GUICtrlListViewGetSelectedCount($ListView) = 0 And $ChangeStatus Then 
        $ChangeStatus = False
        _GUICtrlStatusBarSetText($StatusBar, $TotalItems & ' Item(s)')
    EndIf
    If Not WinActive($Title) Then
        _DisableHotKeys()
        WinWaitActive($Title)
        _EnableHotKeys()
    EndIf
WEnd

Func _ClipPut()
    Local $temp
    $Selected = _GUICtrlListViewGetSelectedIndices($ListView, 1)
    If $Selected = $LV_ERR Then 
        MsgBox(16, 'Copy Seleted Items', 'You need to select at least one item.')
        Return('')
    EndIf
    If IsArray($Selected) Then
        For $x = 1 To $Selected[0]
            $temp &= StringReplace(_GUICtrlListViewGetItemText($ListView, $Selected[$x], -1), '|', @TAB) & @CRLF
        Next
        ClipPut($temp)
    EndIf
EndFunc

Func _EnableHotKeys()
    HotKeySet('^s', '_HotKeyAction')
    HotKeySet('^c', '_HotKeyAction')
    HotKeySet('^a', '_HotKeyAction')
    HotKeySet('^d', '_HotKeyAction')
    HotKeySet('{F5}', '_HotKeyAction')
EndFunc

Func _DisableHotKeys()
    HotKeySet('^s')
    HotKeySet('^c')
    HotKeySet('^a')
    HotKeySet('^d')
    HotKeySet('{F5}')
EndFunc

Func _HotKeyAction()
    Switch @HotKeyPressed
        Case '^s'
            _MenuFileSave()
        Case '^c'
            _ClipPut()
        Case '^a'
            _SelectDeselectItems()
        Case '^d'
            _SelectDeselectItems(0)
        Case '{F5}'
            $TotalItems = 0
            $RemoteComputer = ''
            _GUICtrlListViewDeleteAllItems($ListView)
            _AddItemsToListView(_GetWindowsKey())
            _AddItemsToListView(_GetOfficeKey())
    EndSwitch
EndFunc

Func _Menu()
    Switch @GUI_CtrlId
        Case $MenuEditCopy
            _clipPut()
        Case $MenuEditDeselect
            _SelectDeselectItems(0)
        Case $MenuEditSelect
            _SelectDeselectItems()
        Case $MenuViewRefresh
            $TotalItems = 0
            $RemoteComputer = ''
            _GUICtrlListViewDeleteAllItems($ListView)
            _AddItemsToListView(_GetWindowsKey())
            _AddItemsToListView(_GetOfficeKey())                
        Case $MenuViewReportAll, $MenuViewSelectedItems
            _HtmlHorizontal()
        Case $MenuFileSave
            _MenuFileSave()
    EndSwitch
EndFunc

Func _Refresh()
    GUISetCursor(15, 1)
    $RemoteComputer = StringUpper(GUICtrlRead($RemoteInp))
    If $RemoteComputer <> '' Then
        $temp = Ping($RemoteComputer)
        $error = @error
        GUISetCursor(2, 1)
        If Not $temp Then
            Dim $ErrorMsg[5] = [0, 'host is offline.', 'host is unreachable.', 'bad destination.', 'other errors.']
            MsgBox(16, 'Remote Computer Fail', 'Remote computer ' & $RemoteComputer & ', ' & $ErrorMsg[$error])
            Return('')
        EndIf
        _AddItemsToListView(_GetWindowsKey($RemoteComputer))
        _AddItemsToListView(_GetOfficeKey($RemoteComputer))     
    EndIf
    GUICtrlSetData($RemoteInp, '')
    GUISetCursor(2, 1)
EndFunc

Func _MenuFileSave()
    $temp = FileSaveDialog('Select a filename to save', @ScriptDir, 'Text File (*.txt)|Tab delimited text file (*.txt)' _
        & '|HTML File - Horizontal (*.htm;*.html)|HTML File - Vertical (*.htm;*.html)|XML File (*.xml)')
    ConsoleWrite('File: ' & $temp & @CRLF)
EndFunc

Func _SelectDeselectItems($iState = 1)
    Local $temp = ''
    _GUICtrlListViewSetItemSelState($ListView, -1, $iState)
    If $iState Then $temp = ', ' & _GUICtrlListViewGetSelectedCount($ListView) & ' Selected'    
    _GUICtrlStatusBarSetText($StatusBar, $TotalItems & ' Item(s)' & $temp)
EndFunc

Func _GuiOnEvent()
    GUISetOnEvent($GUI_EVENT_CLOSE, "_SysEventHandler", $MainGUI)
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "_SysEventHandler", $MainGUI)
    GUISetOnEvent($GUI_EVENT_RESTORE, "_SysEventHandler", $MainGUI)
    GUISetOnEvent($GUI_EVENT_MAXIMIZE, "_SysEventHandler", $MainGUI)
    GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_SysEventHandler", $MainGUI)
    GUISetOnEvent($GUI_EVENT_PRIMARYUP, "_SysEventHandler", $MainGUI)
    GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "_SysEventHandler", $MainGUI)
    GUISetOnEvent($GUI_EVENT_SECONDARYUP, "_SysEventHandler", $MainGUI)
    GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "_SysEventHandler", $MainGUI)
    GUISetOnEvent($GUI_EVENT_RESIZED, "_SysEventHandler", $MainGUI)
    GUISetOnEvent($GUI_EVENT_DROPPED, "_SysEventHandler", $MainGUI)
    GUICtrlSetOnEvent($MenuFileExit, '_SysEventHandler')
    GUICtrlSetOnEvent($CloseBtn, '_SysEventHandler')
    GUICtrlSetOnEvent($ListView, '_UpdateStatusBar')
    GUICtrlSetOnEvent($MenuEditCopy, '_Menu')
    GUICtrlSetOnEvent($MenuEditSelect, '_Menu')
    GUICtrlSetOnEvent($MenuEditDeselect, '_Menu')
    GUICtrlSetOnEvent($MenuViewRefresh, '_Menu')
    GUICtrlSetOnEvent($MenuViewReportAll, '_Menu')
    GUICtrlSetOnEvent($MenuViewSelectedItems, '_Menu')
    GUICtrlSetOnEvent($MenuFileSave, '_Menu')
    GUICtrlSetOnEvent($RefreshBtn, '_Refresh')
EndFunc

Func _AddItemsToListView($aArray)   
    If $RemoteComputer = '' Then $RemoteComputer = StringUpper(@ComputerName)
    If $RemoteComputer <> $LastRemoteComputer And $SwitchColor Then
        $SwitchColor = 0
    ElseIf $RemoteComputer <> $LastRemoteComputer Then
        $SwitchColor = 1
    EndIf
    For $x = 1 To UBound($aArray) - 1
        If $aArray[$x][2] <> 'BBBBB-BBBBB-BBBBB-BBBBB-BBBBB' Then
            GUICtrlCreateListViewItem($aArray[$x][0] & '|' & $aArray[$x][1] & '|' & $aArray[$x][2] & '|' & $RemoteComputer, $ListView)
            GUICtrlSetBkColor(-1, $RGBColors[$SwitchColor])
            GUICtrlSetImage(-1, @ScriptFullPath, 207, 0)
            GUICtrlSetOnEvent(-1, '_UpdateStatusBar')
            $TotalItems += 1
        EndIf
    Next
    _GUICtrlListViewSetColumnWidth($ListView, 0, $LVSCW_AUTOSIZE)
    _GUICtrlListViewSetColumnWidth($ListView, 1, $LVSCW_AUTOSIZE)
    _GUICtrlListViewSetColumnWidth($ListView, 2, $LVSCW_AUTOSIZE)
    _GUICtrlListViewSetColumnWidth($ListView, 3, $LVSCW_AUTOSIZE_USEHEADER) 
    _GUICtrlStatusBarSetText($StatusBar, $TotalItems & ' Item(s)')
    $LastRemoteComputer = $RemoteComputer
EndFunc

Func _UpdateStatusBar()
    Local $temp = _GUICtrlListViewGetSelectedCount($ListView)   
    If $temp > 0 Then
        $ChangeStatus = True
        _GUICtrlStatusBarSetText($StatusBar, $TotalItems & ' Item(s), ' & $temp & ' Selected')
    Else
        $ChangeStatus = False
        _GUICtrlStatusBarSetText($StatusBar, $TotalItems & ' Item(s)')
    EndIf
EndFunc

Func _HtmlHorizontal()
    Local $Destination = @TempDir & '\Report.htm'
    
    If FileExists($Destination) Then FileDelete($Destination)
    FileWrite($Destination, '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">')
    FileWrite($Destination, '<html><head><title>Windows Key List</title></head>')
    FileWrite($Destination, '<body>')
    FileWrite($Destination, '<h3>Windows Key List</h3>')
    FileWrite($Destination, '<br><h4>Created by using <a href="http://www.autoitscript.com/" target="newwin">AutoIT</a></h4><p><table border="1" cellpadding="5"><tr bgcolor="E0E0E0">')
    FileWrite($Destination, '<th>Product Name')
    FileWrite($Destination, '<th>Product ID')
    FileWrite($Destination, '<th>Product Key')
    FileWrite($Destination, '<th>Computer Name')
    
    If @GUI_CtrlId = $MenuViewReportAll Then
        For $x = 0 To $TotalItems - 1
            $temp = StringSplit(_GUICtrlListViewGetItemText($ListView, $x, -1), '|')
            FileWrite($Destination, '<tr><td bgcolor=#FFFFFF nowrap>' & $temp[1] & '<td bgcolor=#FFFFFF nowrap>' _
                & $temp[2] & '<td bgcolor=#FFFFFF nowrap>' & $temp[3] & '<td bgcolor=#FFFFFF nowrap>' & $temp[4])
        Next
    Else    
        $Selected = _GUICtrlListViewGetSelectedIndices($ListView, 1)
        If $Selected = $LV_ERR Then 
            MsgBox(16, 'HTML Report - Selected Items', 'You need to select at least one item.')
            Return('')
        EndIf
        If IsArray($Selected) Then
            For $x = 1 To $Selected[0]
                $temp = StringSplit(_GUICtrlListViewGetItemText($ListView, $Selected[$x], -1), '|')
                FileWrite($Destination, '<tr><td bgcolor=#FFFFFF nowrap>' & $temp[1] & '<td bgcolor=#FFFFFF nowrap>' _
                    & $temp[2] & '<td bgcolor=#FFFFFF nowrap>' & $temp[3] & '<td bgcolor=#FFFFFF nowrap>' & $temp[4])
            Next
        EndIf
    EndIf   
        
    FileWrite($Destination, '</table>')
    FileWrite($Destination, '')
    FileWrite($Destination, '</body></html>')
    ShellExecute($Destination)
EndFunc

Func _SysEventHandler()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE, $CloseBtn, $MenuFileExit
            If @GUI_WinHandle <> $MainGUI Then
                GUIDelete(@GUI_WinHandle)
            Else
                Exit
            EndIf
        Case $GUI_EVENT_MINIMIZE
            _DisableHotKeys()
        Case $GUI_EVENT_RESTORE
            _EnableHotKeys()
        Case $GUI_EVENT_MAXIMIZE
        Case $GUI_EVENT_PRIMARYDOWN
        Case $GUI_EVENT_PRIMARYUP
        Case $GUI_EVENT_SECONDARYDOWN
        Case $GUI_EVENT_SECONDARYUP
        Case $GUI_EVENT_MOUSEMOVE
        Case $GUI_EVENT_RESIZED
        Case $GUI_EVENT_DROPPED
    EndSwitch
EndFunc
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

Hi,

there are some details in the thread (see my sig) [the script is very old] :mellow:

Like

#include <GUIConstantsEx.au3>
; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1 beta
; Author: Thorsten Meger
;
; Script Function:
; Windows XP Information displayed in a Gui
;
; ----------------------------------------------------------------------------

$GUI = GUICreate("", 380, 315, -1, -1)
GUISetFont(9, 700, -1, "MS Sans Serif")

$windowsInformation_L = GUICtrlCreateLabel(" Windows Information", 5, 3, 290, 25)
$status_L = GUICtrlCreateLabel("Information read ...", 20, 280, 200, 20)
$description_L = GUICtrlCreateLabel("Description", 20, 58, 100, 20)
$windowsType_L = GUICtrlCreateLabel("WindowsType", 20, 83, 100, 20)
$serialNumber_L = GUICtrlCreateLabel("SerialNumber", 20, 108, 100, 20)
$ProductKey_L = GUICtrlCreateLabel("ProductKey", 20, 133, 100, 20)
$InstallDate_L = GUICtrlCreateLabel("InstallDate", 20, 158, 100, 20)
$LastBootUpTime_L = GUICtrlCreateLabel("LastBootUpTime", 20, 183, 100, 20)
$RegisteredOwner_L = GUICtrlCreateLabel("RegisteredOwner", 20, 208, 100, 20)
$officeKey_L = GUICtrlCreateLabel("OfficeKey", 20, 233, 100, 20)

$description_I = GUICtrlCreateInput("", 125, 55, 235, 20)
$windowsType_I = GUICtrlCreateInput("", 125, 80, 235, 20)
$serialNumber_I = GUICtrlCreateInput("", 125, 105, 235, 20)
$ProductKey_I = GUICtrlCreateInput("", 125, 130, 235, 20)
$InstallDate_I = GUICtrlCreateInput("", 125, 155, 235, 20)
$LastBootUpTime_I = GUICtrlCreateInput("", 125, 180, 235, 20)
$RegisteredOwner_I = GUICtrlCreateInput("", 125, 205, 235, 20)
$officeKey_I = GUICtrlCreateInput("", 125, 230, 235, 20)

$informationPanel_G = GUICtrlCreateGroup("Information Panel", 10, 35, 360, 225)
$status_G = GUICtrlCreateGroup("Status", 10, 265, 360, 40)

$font = "Comic Sans MS"
GUICtrlSetColor($windowsInformation_L, 0xff0000)
GUICtrlSetFont($windowsInformation_L, 16, 700, 4, $font)

$progressbar = GUICtrlCreateProgress(140, 278, 220, 20)

Global $product = ""
Global $counter = 3
Global $wait = 150

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $counter = 3 Then
        Sleep(1000)
        GUICtrlSetData($status_L, "Initialize ... " & $counter)
        progress()
        $counter -= 1
    ElseIf $counter = 2 Then
        GUICtrlSetData($status_L, "Initialize ... " & $counter)
        progress()
        $counter -= 1
    ElseIf $counter = 1 Then
        GUICtrlSetData($status_L, "Initialize ... " & $counter)
        progress()
        $counter -= 1
    ElseIf $counter = 0 Then
        GUICtrlSetData($status_L, "Ready ...")
        progress()
        $counter -= 1
    ElseIf $counter = -1 Then
        Dim $Bin = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductID")
        Dim $key4RegisteredOwner = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
        $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
        $colSettings = $objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")

        For $objOperatingSystem In $colSettings
        Next
        GUICtrlSetData($description_I, StringMid($objOperatingSystem.Description, 1))
        GUICtrlSetData($windowsType_I, '(' & @OSVersion & ') ' & StringMid($objOperatingSystem.Caption, 19))
        GUICtrlSetData($serialNumber_I, StringMid($objOperatingSystem.SerialNumber, 1))
        GUICtrlSetData($ProductKey_I, DecodeProductKey($Bin))
        GUICtrlSetData($InstallDate_I, WMIDateStringToDate($objOperatingSystem.InstallDate))
        GUICtrlSetData($LastBootUpTime_I, WMIDateStringToDate($objOperatingSystem.LastBootUpTime))
        GUICtrlSetData($RegisteredOwner_I, RegRead($key4RegisteredOwner, "RegisteredOwner"))
        GUICtrlSetData($officeKey_I, getOfficeKey())
        GUICtrlSetData($officeKey_L, "Office " & $product)
        $counter -= 1
    ElseIf $counter < -1 Then
        Select
            Case $msg = $GUI_EVENT_CLOSE
                GUICtrlSetState($progressbar, $GUI_HIDE)
                GUICtrlSetData($status_L, "CU Mega")
                Sleep(2000)
                ExitLoop
        EndSelect
    EndIf
WEnd
Exit

Func DecodeProductKey($BinaryDPID)
    Local $bKey[15]
    Local $sKey[29]
    Local $Digits[24]
    Local $Value = 0
    Local $hi = 0
    Local $n = 0
    Local $i = 0
    Local $dlen = 29
    Local $slen = 15
    Local $Result

    $Digits = StringSplit("BCDFGHJKMPQRTVWXY2346789", "")
    $BinaryDPID = StringMid($BinaryDPID, 105, 30)
    For $i = 1 To 29 Step 2
        $bKey[Int($i / 2) ] = Dec(StringMid($BinaryDPID, $i, 2))
    Next
    For $i = $dlen - 1 To 0 Step - 1
        If Mod(($i + 1), 6) = 0 Then
            $sKey[$i] = "-"
        Else
            $hi = 0
            For $n = $slen - 1 To 0 Step - 1
                $Value = BitOR(BitShift($hi, -8), $bKey[$n])
                $bKey[$n] = Int($Value / 24)
                $hi = Mod($Value, 24)
            Next
            $sKey[$i] = $Digits[$hi + 1]
        EndIf
    Next
    For $i = 0 To 28
        $Result = $Result & $sKey[$i]
    Next
    Return $Result
EndFunc   ;==>DecodeProductKey

Func WMIDateStringToDate($dtmDate)
    Return (StringMid($dtmDate, 7, 2) & "/" & _
            StringMid($dtmDate, 5, 2) & "/" & StringLeft($dtmDate, 4) _
             & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate, 13, 2))
EndFunc   ;==>WMIDateStringToDate

Func progress()
    If $counter = 3 Then
        For $i = 0 To 20 Step 1
            GUICtrlSetData($progressbar, $i)
            Sleep($wait / 20)
        Next
    ElseIf $counter = 2 Then
        For $i = 20 To 50 Step 1
            GUICtrlSetData($progressbar, $i)
            Sleep($wait / 30)
        Next
    ElseIf $counter = 1 Then
        For $i = 50 To 80 Step 1
            GUICtrlSetData($progressbar, $i)
            Sleep($wait / 30)
        Next
    ElseIf $counter = 0 Then
        For $i = 80 To 100 Step 1
            GUICtrlSetData($progressbar, $i)
            Sleep($wait / 20)
        Next
        GUICtrlSetState($progressbar, $GUI_SHOW)
    EndIf
EndFunc   ;==>progress

Func getOfficeKey()
    Local $List[1]
    Local $i = 1
    $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Common\InstallRoot", "Path")
    If $var <> "" Then
        $product = "2003"
        Dim $officeKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Registration"
    Else
        $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0\Common\InstallRoot", "Path")
        If @error <> 0 Then
            GUICtrlSetData($status_L, "Info: Unable to find installationPath, maybe no Office installed!")
            Return "No Office XP or 2003 found"
        EndIf
        If $var <> "" Then
            $product = "XP"
            Dim $officeKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0\Registration"
        EndIf
    EndIf
    Dim $var = RegEnumKey($officeKey, $i)
    If @error <> 0 Then
        GUICtrlSetData($status_L, "Info: Unable to find REG_BINARY 'DigitalProductID', maybe no Office installed!")
        Return "No Office XP or 2003 found"
    Else
        $List[$i - 1] = RegRead($officeKey & "\" & $var, "DigitalProductID")
        If $List[$i - 1] = "" Then
            GUICtrlSetData($status_L, "Info: Unable to find REG_BINARY 'DigitalProductID', maybe no Office installed!")
        Else
            $key = $List[$i - 1]
            Return DecodeProductKey($key)
        EndIf
    EndIf
EndFunc   ;==>getOfficeKey

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Xenobiologist - I believe that bout says it all.. it does both!

What does that mean?

Mega

Edited by Xenobiologist

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • 4 weeks later...

Updated the getOfficeKey() func to add support for 2k7.

Func getOfficeKey()
    Local $List[1]
    Local $i = 1
    $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Common\InstallRoot", "Path")
    If $var <> "" Then
        $product = "2003"
        Dim $officeKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Registration"
    Else
        $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0\Common\InstallRoot", "Path")
        If $var <> "" Then
            $product = "XP"
            Dim $officeKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0\Registration"
        Else
            $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Common\InstallRoot", "Path")
            If $var <> "" Then
                $product = "2007"
                Dim $officeKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Registration"
            EndIf
        EndIf
    EndIf
    Dim $var = RegEnumKey($officeKey, $i)
    If @error <> 0 Then
        GUICtrlSetData($status_L, "Info: Unable to find REG_BINARY 'DigitalProductID', maybe no Office installed!")
        Return "No Office XP or 2003 found"
    Else
        $List[$i - 1] = RegRead($officeKey & "\" & $var, "DigitalProductID")
        If $List[$i - 1] = "" Then
            GUICtrlSetData($status_L, "Info: Unable to find REG_BINARY 'DigitalProductID', maybe no Office installed!")
        Else
            $key = $List[$i - 1]
            Return DecodeProductKey($key)
        EndIf
    EndIf
EndFunc  ;==>getOfficeKey
Edited by sariel
Link to comment
Share on other sites

  • 3 months later...

How do you know what's wrong? Maybe you compared wrong.

I just checked it and the algrithm is wrong. I did much the same thing a few years ago and it returns the correct results.

It has not been touched in 3 years so there is some seriously outdated code in it.

http://dundats.mvps.org/beta/RegInfo4.zip

I'll dig out the script one of these days and post the algorithm in this thread.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I just checked it and the algrithm is wrong. I did much the same thing a few years ago and it returns the correct results.

It has not been touched in 3 years so there is some seriously outdated code in it.

http://dundats.mvps.org/beta/RegInfo4.zip

I'll dig out the script one of these days and post the algorithm in this thread.

AutoIt's RegRead() is changed. That would require to change 105 to 107 in scripts (key offset).

This also shows that using string functions with binary data is not to be recommended.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...