Jump to content

VBScript to AutoIt Converter


Recommended Posts

This is a converter for a VBScript (5.6) to AutoIt (3.1.1) converter.

i hope it is useful.

There are many thinks to add at the moment.

To test it you need all attach files.

Comments are welcome.

Version 0.4

- Fixing error message in GUI

- Workaround for wscript.echo

- Better handling of parenthesis for sub's

- Implement ReDim

- Set default destination file name in gui

- Added some new commands in VATable.txt

- Improvements for select constructs

Version 0.3

- Added command line switch (vaconvert VBSCRIPTFILE)

- Added Gui to select source and destination file (tahnks to gafrost)

- Better handlung for prodedure calls

- Fixing other errors (e.g. endless loop)

Version 0.2

- Add some simple replace commands (VATable.txt)

- Improve Select case

- Find variables without Dim

- Find Constants

- Add List of VBCommands (VACommands.txt)

Version 0.1

- Better function handling

- Added most VBScript functions

- Include handling

Version 0.01

- First public release

Added v0.4 10.06.2005

Added v0.3 08.06.2005

Added v0.2 06.06.2005

Added v0.1 05.06.2005

Added v0.01 04.06.2005

VAConvert.04.zip

Edited by bkemmler
Link to comment
Share on other sites

This is the first public release (v0.02) of a VBScript (5.6) to AutoIt (3.1.1) converter.

i hope it is useful.

There are many thinks to add at the moment.

To test it you need all attach files.

Comments are welcome.

<{POST_SNAPBACK}>

Very nicely done! :(
Link to comment
Share on other sites

can it goes from autoit to VB as well?

because although I dont know vb I do know autoIT and VB is necessary for some things

<{POST_SNAPBACK}>

No it is only converting from VBScript to AutoIt.

Everything you want to do with VBScript should be possible with AutoIt

Link to comment
Share on other sites

Thought it could use a little gui interface, this was quick and dirty

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1
; Author:         Bernd Kemmler
;
; Script Function:
;    Convert VBScript to AutoIt 3.1.1
;
; Version 0.02
; ----------------------------------------------------------------------------
; To Do:
; o Special handling of:  SELECT, Func Return, Class Blocks, Dim, Do loop, Redim, Function
; o GUI to select the source, destination
; o include handling
; ...

;Options
#region Options
#NoTrayIcon
AutoItSetOption("MustDeclareVars", 1)
AutoItSetOption("RunErrorsFatal", 0)
AutoItSetOption("TrayIconHide", 1)

; Variable declarations
#region Variables
Global Const $strVersion = "0.02"
Global Const $strMask = "#"
Global Const $strRemark = "'"
Global Const $strSpecial = ".,()<>="
Global $arrVBFile
Global $arrVBFileMarked
Global $arrAU3File
Dim $Lbl_Source, $Lbl_Dest, $Btn_Source, $Btn_Dest, $Btn_Convert, $Btn_Exit, $msg
#endregion

; Include files
#region Includes
#include <bk-array.au3>
#include <bk-file.au3>
#include <bk-string.au3>
#include <array.au3>
#include <math.au3>
#endregion
#region --- GuiBuilder code Start ---
; Script generated by AutoBuilder 0.5 Prototype

#include <GuiConstants.au3>

GuiCreate("Convert VBScript to AutoIt 3.1.1++", 500, 208)

$Lbl_Source = GuiCtrlCreateLabel("Source File", 30, 30, 400, 20)
$Lbl_Dest = GuiCtrlCreateLabel("Destination File", 30, 70, 400, 20)
$Btn_Source = GuiCtrlCreateButton("Select...", 420, 20, 70, 30)
$Btn_Dest = GuiCtrlCreateButton("Select...", 420, 60, 70, 30)
$Btn_Convert = GuiCtrlCreateButton("Convert", 154, 130, 70, 30)
$Btn_Exit = GuiCtrlCreateButton("Exit", 264, 130, 70, 30)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit
        ExitLoop
    Case $msg = $Btn_Source
        GUICtrlSetData($Lbl_Source,FileOpenDialog ( "Select VBS Source File", ".", "VBS (*.vbs)" , 3 ))
    Case $msg = $Btn_Dest
        GUICtrlSetData($Lbl_Dest,FileOpenDialog ( "Select Au3 Dest File", ".", "AutoIt (*.au3)" ))
    Case $msg = $Btn_Convert
        Convert(GUICtrlRead($Lbl_Source),GUICtrlRead($Lbl_Dest))
    EndSelect
WEnd
Exit
#endregion --- GuiBuilder generated code End ---


Func Convert($Source, $Dest)
    ReadVBFile($Source)
    MarkSpecialParts()
    ReplaceSimpleCommands()
    ChangeVariables()
    WriteAU3File($Dest)
EndFunc
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Wow am I slow, I just realized that i need the commands.txt file as well :(

Also, are there plans to automatically change the variable into the $variable_name format?

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
Share on other sites

Can I throw a spanner in to the works..... :(

I just found a relatively simple vbs script to do a test.

The converted script still needs alot of work done to make it usable in Aut3.

Am I doing it right!

I wasn't too sure what I was supposed to do with the commands.txt

Here is my test vbs script - can you check if it works OK for you.

' FreeSpace.vbs,  Version 1.00
' Display free disk space for all local drives.
'
' Written by Rob van der Woude
' http://www.robvanderwoude.com


' Check command line parameters
Select Case WScript.Arguments.Count
    Case 0
        ' Default if none specified is local computer (".")
        Set objWMIService = GetObject( "winmgmts://./root/cimv2" )
        Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
        For Each objItem in colItems
            strComputer = objItem.Name
        Next
    Case 1
        ' Command line parameter can either be a computer name
        ' or "/?" to request online help
        strComputer = Wscript.Arguments(0)
        if InStr( strComputer, "?" ) > 0 Then Syntax
    Case Else
        ' Maximum is 1 command line parameter
        Syntax
End Select

Display( strComputer )
WScript.Quit(0)


Function Display( strComputer )
    strMsg = vbCrLf & "Name:" & vbTab & "Drive:" & vbTab & "Size:" & _
             vbTab & "Free:" & vbTab & "% Free:" & vbCrLf & "=====" & _
             vbTab & "======" & vbTab & "=====" & vbTab & "=====" & _
             vbTab & "=======" & vbCrLf
    On Error Resume Next
    Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
    If Err.Number Then
        WScript.Echo vbCrLf & "Error # " & CStr( Err.Number ) & _
                     " " & Err.Description
        Err.Clear
        Syntax
    End If
    On Error GoTo 0
    ' Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk where MediaType=12",,48)
    Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk where DriveType=3",,48)
    For Each objItem in colItems
        strMsg = strMsg & strComputer & vbTab & _
                 objItem.Name & vbTab & _
                 CStr( Int( 0.5 + ( objItem.Size / 1073741824 ) ) ) & _
                 vbTab & _
                 CStr( Int( 0.5 + ( objItem.FreeSpace / 1073741824 ) ) ) & _
                 vbTab & _
                 CStr( Int( 0.5 + ( 100 * objItem.FreeSpace / objItem.Size) ) ) & _
                 vbCrLf
    Next
    WScript.Echo strMsg
End Function


Sub Syntax
    strMsg = vbCrLf & "FreeSpace.vbs,  Version 1.00" & vbCrLf & _
             "Display free disk space for all local drives." & vbCrLf & _
             vbCrLf & _
             "Usage:  CSCRIPT  FREESPACE.VBS  [ computer_name ]" & _
             vbCrLf & vbCrLf & _
             "Where:  " & Chr(34) & "computer_name" & Chr(34) & _
             " is the name of a WMI enabled computer on the network" & _
             vbCrLf & vbCrLf & _
             "Written by Rob van der Woude" & vbCrLf & _
             "http://www.robvanderwoude.com" & vbCrLf
    WScript.Echo strMsg
    WScript.Quit(1)
End Sub

Thanks

Link to comment
Share on other sites

Can I throw a spanner in to the works..... :(

I just found a relatively simple vbs script to do a test.

The converted script still needs alot of work done to make it usable in Aut3.

Am I doing it right!

I wasn't too sure what I was supposed to do with the commands.txt

Here is my test vbs script - can you check if it works OK for you.

Thanks

<{POST_SNAPBACK}>

You are right. With this kind of script it will have problems. The actual version needs DIM's for the variables.
Link to comment
Share on other sites

I was working on my own script, and the WScript.Echo wasn't being translated...I don't know if it was just my script or...

<{POST_SNAPBACK}>

There is no command like WScript.Echo in AutoIt. And if you do not want to use WSH, it is not a good idea to use the WScript object.
Link to comment
Share on other sites

Wow am I slow, I just realized that i need the commands.txt file as well :(

Also, are there plans to automatically change the variable into the $variable_name format?

<{POST_SNAPBACK}>

If you use the DIM command in VBScript it is working already.
Link to comment
Share on other sites

Link to comment
Share on other sites

i believe right now it only converts a file called 'test.vbs' located in the scripts directory.

As for WScript.Echo, can't you just do 'MsgBox(0, "", $variable)'?

Edited by MSLx Fanboy

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
Share on other sites

This script might be useful.

But untill there is no readme file, explaining on how to use it, it is NOT useful.

Hopefully more help is on the way.

<{POST_SNAPBACK}>

There is a gui now available. I hope this helps.
Link to comment
Share on other sites

@bkemmler

Thanks for the new version. Now help file needed anymore since the GUI runs OK.

I tested a VBscript which should show the OS version of your system.

The converion was done 95 % OK.

Which is a pretty good job.

The only thing you need to build in into you conversion is the translation from Wscript.Echo -> Msgbox to show the output.

At the moment there is no output after the conversion.

Vbscript :
'Returns the name and version number of the operating system installed on a computer.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
    Wscript.Echo objOperatingSystem.Caption & " " & _
        objOperatingSystem.Version
Next

AuITScript:
;Returns the name and version number of the operating system installed on a computer.

$strComputer = "."
 $objWMIService = ObjGet("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
 $colOperatingSystems = $objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For $objOperatingSystem in $colOperatingSystems
;VA  Wscript.Echo $objOperatingSystem.Caption & " " & _
        $objOperatingSystem.Version()
Next


SEE COMMENT;VA where there has been no translation done !!

This should have been :

Msgbox(0, "VBScript to AutoIt Converter v0.3", $objOperatingSystem.Caption & " " & $objOperatingSystem.Version())

I hope this feedback helps you improving.

It only needs a little bit extra tweaking.

Keep up the good work !!

Link to comment
Share on other sites

@gafrost

@bkemmler

The explanation in the help, of the ConsoleWrite is :

Writes data to a stream that text editors can SOMETIMES read.

- The first reason whu this should not be shosen is of the SOMETIMES possibility.

If you like this option VBscript has an other command that produces output to

console. This command should than be translated to ConsoleWrite.

- The second reason not to choose this is, that not an exact conversion of how the

behaviour was in VBscript

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