Jump to content
Celtic88

Convert VBS to AutoIT!

Recommended Posts

Celtic88

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

Share this post


Link to post
Share on other sites
water

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:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Celtic88

I am a newbie in programming , and I do not know anything in vbs :(

Share this post


Link to post
Share on other sites
water

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:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Celtic88

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

Share this post


Link to post
Share on other sites
water

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:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Celtic88

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

Share this post


Link to post
Share on other sites
ricky

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

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

Share this post


Link to post
Share on other sites
water

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:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
ricky

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

Share this post


Link to post
Share on other sites
JLogan3o13

@rickyyou need to provide a little more than "it doesn't work". What is happening? What are you seeing? Are you getting an error? etc.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
ricky

Right, sorry, no error, it don't give the good license number.

Edited by ricky

Share this post


Link to post
Share on other sites
JLogan3o13

Again, can you expand on this? Does it return anything at all? Just a blank? 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
ricky

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

Share this post


Link to post
Share on other sites
ricky

Nobody can help me to fix this problem? Or translate the VBS script to autoit?

 

Share this post


Link to post
Share on other sites
mLipok
On 29.01.2016 at 4:48 PM, ricky said:

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

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


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-03-17

Share this post


Link to post
Share on other sites
ricky

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

Share this post


Link to post
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

×