Jump to content

Convert VBS to AutoIT!


Celtic88
 Share

Recommended Posts

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
Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • 1 month later...

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
Link to comment
Share on other sites

  • 2 years later...

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
Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

@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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • 3 weeks later...
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:
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:

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 APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

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 * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

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 * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

Link to comment
Share on other sites

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
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...