Jump to content

Recommended Posts

Posted

I'm trying to convert this vbs script to autoit. I used two different converter and had no luck. Can anyone please help me?

Set WshShell = CreateObject("WScript.Shell")

key = "HKLMSOFTWAREMicrosoftWindows NTCurrentVersion"
digitalId = WshShell.RegRead(key & "DigitalProductId")
 
ProductName = "Product Name : " & WshShell.RegRead(key & "ProductName") & vbNewLine 
ProductId = "Product Id : " & WshShell.RegRead(key & "ProductId") & vbNewLine 
ProductKey = "Install Key : " & Converted(digitalId)
 
ProductId = ProductName & ProductId & ProductKey
 
boutons = vbYesNo + vbQuestion
If vbYes = MsgBox(ProductId & vblf & vblf & "Save to a file ?", boutons, "Windows Infos") then
Save ProductId
End if
 
Function Converted(id)
Const OFFSET = 52
i = 28
Chars = "BCDFGHJKMPQRTVWXY2346789"
Do
Cur = 0
x = 14
Do
Cur = Cur * 256
Cur = id(x + OFFSET) + Cur
id(x + OFFSET) = (Cur 24) And 255
Cur = Cur Mod 24
x = x -1
Loop While x >= 0
i = i - 1
Converted = Mid(Chars, Cur + 1, 1) & Converted
If (((29 - i) Mod 6) = 0) And (i <> -1) Then
i = i -1
Converted = "-" & Converted
End If
Loop While i >= 0
End Function
 
Function Save(data)
Const ForWRITING = 2
Const asASCII = 0
Dim fso, f, fName, ts
 
today = FormatDateTime(Date, vbLongDate) & vbnewline
fName = "OS Key.txt"
 
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CreateTextFile fName
Set f = fso.GetFile(fName)
Set f = f.OpenAsTextStream(ForWRITING, asASCII)
f.Writeline today
f.Writeline data
f.Close
End Function
Posted

Doesn't look too complex.

As the converters didn't help, did you try it yourself? What have you created so far? Which problems did you encounter?

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)

Start with what you know about AutoIt and convert what looks similar in VB.

This

Set WshShell = CreateObject("WScript.Shell")
key = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
digitalId = WshShell.RegRead(key & "DigitalProductId")
 
ProductName = "Product Name : " & WshShell.RegRead(key & "ProductName") & vbNewLine 
ProductId = "Product Id : " & WshShell.RegRead(key & "ProductId") & vbNewLine 
ProductKey = "Install Key : " & Converted(digitalId)
 
ProductId = ProductName & ProductId & ProductKey
 
boutons = vbYesNo + vbQuestion
If vbYes = MsgBox(ProductId & vblf & vblf & "Save to a file ?", boutons, "Windows Infos") then
Save ProductId
End if
can easily be converted to

$key = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
$digitalId = RegRead($key, "DigitalProductId")
 
$ProductName = "Product Name : " & RegRead($key, "ProductName") & @LF
$ProductId = "Product Id : " & RegRead($key, "ProductId") & @LF
$ProductKey = "Install Key : " & Converted($digitalId)
 
$ProductId = $ProductName & $ProductId & $ProductKey
 
If MsgBox(4, "Windows Infos", $ProductId & @LF & @LF & "Save to a file ?") = 6 Then
  Save($ProductId)
EndIf
Try the rest and if you have problems, ask again. Edited by water

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

re ,

Cur = id(x + OFFSET) + Cur
id(x + OFFSET) = (Cur 24) And 255

How to convert this code to  autoit

These attempt

MsgBox(0, 'Сообщение', Converted(RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\", "DigitalProductId")))

Func Converted($id)
    Local $Return
    Const $OFFSET = 52
    $i = 28
    $Chars = "BCDFGHJKMPQRTVWXY2346789"
    Do
        $Cur = 0
        $x = 14
        Do
            $Cur = $Cur * 256
            
            $Cur = ($x + $OFFSET) + $Cur ;; ?
            ($x + $OFFSET) = ($Cur / 24) And 255
            
            $Cur = Mod($Cur , 24)
            $x = $x - 1
        Until $x < 0
        $i = $i - 1
        $Return = StringMid($Chars, $Cur + 1, 1)  & $Return
        If (Mod ((29 - $i) ,6) = 0) And ($i <> -1) Then
            $i = $i - 1
            $Return &= "-"
        EndIf
    Until $i < 0
    Return $Return
EndFunc   ;==>Converted
Posted

  On 9/30/2013 at 11:58 AM, Mrbenkali said:

Cur = id(x + OFFSET) + Cur

id(x + OFFSET) = (Cur 24) And 255

 

How to convert this code to  autoit

$Cur = id[$x + $Offset] + $Cur
id[$x + $OFFSET] = BitAnd(Int($Cur/24)), 255)

 Looks like id is treated as an array. But I could be wrong.

My UDFs and Tutorials:

  Reveal hidden contents

 

  • 1 month later...
Posted (edited)

I finally found a solution : D 

 

- Add office cd key 

MsgBox(0, ' Retrieve Windows Product Info ', _GetWindowskey())

Func _GetWindowskey()
    Local $WindowscdKEy, $WindowsRegkey = 'HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
    
    $WindowscdKEy = "Product Name : " & RegRead($WindowsRegkey, 'ProductName') & @CRLF
    $WindowscdKEy &= "Product Id : " & RegRead($WindowsRegkey, 'ProductId') & @CRLF
    $WindowscdKEy &= "Install Key : " & _Converted(RegRead($WindowsRegkey, 'DigitalProductId')) & @CRLF
    
    Local $OfficeCdkey, $ZOFkey, $Getnumkey
    Dim $OfficeVer[5] = ["10.0", "11.0", "12.0", "14.0", "15.0"]
    For $i = 0 To 4
        $ZOFkey = 'HKLM\SOFTWARE\Microsoft\Office\' & $OfficeVer[$i] & '\Registration\'
        $Getnumkey = _Getnumkey($ZOFkey)
        If $Getnumkey[0] <> "" Then
            For $Ii = 1 To $Getnumkey[0]
                
                $OfficeCdkey &= "Product Name : " & RegRead($ZOFkey & $Getnumkey[$Ii], 'ProductName') & @CRLF
                $OfficeCdkey &= "Product Id : " & RegRead($ZOFkey & $Getnumkey[$Ii], 'ProductId') & @CRLF
                $OfficeCdkey &= "Install Key : " & _Converted(RegRead($ZOFkey & $Getnumkey[$Ii], 'DigitalProductId')) & @CRLF & @CRLF
                
            Next
        EndIf
    Next
    Return '-Windows key : ' & @CRLF & @CRLF & $WindowscdKEy & @CRLF & '-Office Key : ' & @CRLF & @CRLF & $OfficeCdkey
EndFunc   ;==>_GetWindowskey

Func _Converted($id)
    $id = _KEyArry($id)
    Local $Converted, $Cur, $x
    Local Const $OFFSET = 52
    Local $i = 28
    Local $Chars = "BCDFGHJKMPQRTVWXY2346789"
    Do
        $Cur = 0
        $x = 14
        Do
            $Cur = $Cur * 256
            $Cur = $id[$x + $OFFSET] + $Cur
            $id[$x + $OFFSET] = BitAND(Int(($Cur / 24)), 255)
            $Cur = Mod($Cur, 24)
            $x = $x - 1
        Until $x < 0
        $i = $i - 1
        $Converted = StringMid($Chars, $Cur + 1, 1) & $Converted
        If Mod((29 - $i), 6) = 0 And $i <> -1 Then
            $i = $i - 1
            $Converted = "-" & $Converted
        EndIf
    Until $i < 0
    Return $Converted
EndFunc   ;==>_Converted
Func _KEyArry($BIn)
    Local $Count
    Local $Slen = StringLen($BIn)
    Dim $keyarray[BinaryLen($BIn)]
    For $i = 3 To $Slen Step 2
        $keyarray[$Count] = Dec(StringMid($BIn, $i, 2))
        $Count += 1
    Next
    Return $keyarray
EndFunc   ;==>_KEyArry
Func _Getnumkey($Skey)
    Local $i, $Vkey
    Dim $NumkeyArry[1]
    While True
        $i += 1
        $Vkey = RegEnumKey($Skey, $i)
        If @error Then ExitLoop
        ReDim $NumkeyArry[$i + 1]
        $NumkeyArry[0] = $i
        $NumkeyArry[$i] = $Vkey
    WEnd
    Return $NumkeyArry
EndFunc   ;==>_Getnumkey
Edited by Mrbenkali
  • 2 years later...
Posted (edited)

Hello,

AutoIt v 3.3.14.1

sorry to open again this topic, but the script above doesn't work.

  Quote

"C:\Temp\temp-12.au3" (39) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$Cur = $id[$x + $OFFSET] + $Cur
$Cur = ^ ERROR

Expand  

Could you please help me? I don't understand the goal of the function "Func _KEyArry"! In the VBS script is more easy!

For information, the topic with a vbs script working : http://www.eightforums.com/installation-setup/13555-how-do-i-find-my-product-key-post146433.html#post146433

Thanks for your help

Edited by ricky
Add version
Posted (edited)

This works with Windows 7 64 bit and Office 10 32 bit:

MsgBox(0, ' Retrieve Windows Product Info ', _GetWindowskey())

Func _GetWindowskey()
    Local $WindowscdKEy, $WindowsRegkey = 'HKLM64\SOFTWARE\Microsoft\Windows NT\CurrentVersion'

    $WindowscdKEy = "Product Name : " & RegRead($WindowsRegkey, 'ProductName') & @CRLF
    $WindowscdKEy &= "Product Id : " & RegRead($WindowsRegkey, 'ProductId') & @CRLF
    $WindowscdKEy &= "Install Key : " & _Converted(RegRead($WindowsRegkey, 'DigitalProductId')) & @CRLF

    Local $OfficeCdkey, $ZOFkey, $Getnumkey
    Dim $OfficeVer[5] = ["10.0", "11.0", "12.0", "14.0", "15.0"]
    For $i = 0 To 4
        $ZOFkey = 'HKLM\SOFTWARE\Microsoft\Office\' & $OfficeVer[$i] & '\Registration\'
        $Getnumkey = _Getnumkey($ZOFkey)
        If $Getnumkey[0] <> "" Then
            For $Ii = 1 To $Getnumkey[0]
                $sProductName = RegRead($ZOFkey & $Getnumkey[$Ii], 'ProductName')
                If @error Then $sProductName = RegRead($ZOFkey & $Getnumkey[$Ii], 'ProductNameNonQualified')
                $sProductId = RegRead($ZOFkey & $Getnumkey[$Ii], 'ProductId')
                $sProductDId = RegRead($ZOFkey & $Getnumkey[$Ii], 'DigitalProductId')
                If @error = 0 Then
                    $OfficeCdkey &= "Product Name : " & $sProductName & @CRLF
                    $OfficeCdkey &= "Product Id : " & $sProductId & @CRLF
                    $OfficeCdkey &= "Install Key : " & _Converted($sProductDId) & @CRLF & @CRLF
                EndIf
            Next
        EndIf
    Next
    Return '-Windows key : ' & @CRLF & @CRLF & $WindowscdKEy & @CRLF & '-Office Key : ' & @CRLF & @CRLF & $OfficeCdkey
EndFunc   ;==>_GetWindowskey

Func _Converted($id)
    $id = _KEyArry($id)
    Local $Converted, $Cur, $x
    Local Const $OFFSET = 52
    Local $i = 28
    Local $Chars = "BCDFGHJKMPQRTVWXY2346789"
    Do
        $Cur = 0
        $x = 14
        Do
            $Cur = $Cur * 256
            $Cur = $id[$x + $OFFSET] + $Cur
            $id[$x + $OFFSET] = BitAND(Int(($Cur / 24)), 255)
            $Cur = Mod($Cur, 24)
            $x = $x - 1
        Until $x < 0
        $i = $i - 1
        $Converted = StringMid($Chars, $Cur + 1, 1) & $Converted
        If Mod((29 - $i), 6) = 0 And $i <> -1 Then
            $i = $i - 1
            $Converted = "-" & $Converted
        EndIf
    Until $i < 0
    Return $Converted
EndFunc   ;==>_Converted
Func _KEyArry($BIn)
    Local $Count
    Local $Slen = StringLen($BIn)
    Dim $keyarray[BinaryLen($BIn)]
    For $i = 3 To $Slen Step 2
        $keyarray[$Count] = Dec(StringMid($BIn, $i, 2))
        $Count += 1
    Next
    Return $keyarray
EndFunc   ;==>_KEyArry
Func _Getnumkey($Skey)
    Local $i, $Vkey
    Dim $NumkeyArry[1]
    While True
        $i += 1
        $Vkey = RegEnumKey($Skey, $i)
        If @error Then ExitLoop
        ReDim $NumkeyArry[$i + 1]
        $NumkeyArry[0] = $i
        $NumkeyArry[$i] = $Vkey
    WEnd
    Return $NumkeyArry
EndFunc   ;==>_Getnumkey

 

Edited by water

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)

Hello,

thanks for your help, but it doesn't work in Windows server 2012, but the vbs under the link above works, but I don't understand the difference.

Who can help me?

Edited by ricky
  • 3 weeks later...
Posted
  On 1/29/2016 at 3:48 PM, ricky said:

It returns a license key, but not the good one.

Expand  

So try to find your licencse key via email or any other documents which you get from the developer.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Thanks for your answer, but it's not the problem.

I have the sticker with my license key (Windows server 2012).

But I as already integrated a script in a program home made, but it returns not the good license number.

But in my answer above #8, the script shows the good license. I just want to convert this script to autoit...

 

Edited by ricky

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
  • Recently Browsing   0 members

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