Sign in to follow this  
Followers 0
jcchipper2

convert vb to autoit3

4 posts in this topic

I'm trying to convert this small VB script to autoit3 and have hit a snag at the very end:

VB Script:

set env = CreateObject("Microsoft.SMS.TSEnvironment")

Name = inputbox("Enter OS Selection: XP or Vista" ,"OS Selection:",env("OSType"),400,0)

env("OSType") = Name

AutoIT:

CODE
#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

Dim $oShell

Opt('MustDeclareVars', 1)

OSDetect()

Func OSDetect()

Local $msg, $button_1, $OSType, $name

GUICreate("OS Deploy", 300, 125)

GUICtrlCreateLabel("Select Operating System to Deploy: XP or Vista", 20, 20, 170, 40)

$OSType = GUICtrlCreateCombo("", 30, 80, 100, 10) ; create first item

GUICtrlSetData(-1, "XP|Vista") ; add other item snd set a new default

$button_1 = GUICtrlCreateButton("Okay", 170, 65, 120, 40)

GUISetState()

; Run the GUI until the dialog is closed

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $Button_1

$oShell = ObjCreate("Microsoft.SMS.TSEnvironment")

$name = GUICtrlRead($OSType)

MsgBox(0,"I have semi worked", $name)

$oShell("OSType") = $name

ExitLoop

EndSelect

WEnd

EndFunc

When I run the above code I get:

Line -1:

Error: Expected a "=" operator in assignment statement

I know the code is failing after the Msgbox.

Any help would be appreciated.

Share this post


Link to post
Share on other sites



It's failing because $oShell is not an object, meaning your ObjCreate() failed. I don't think AutoIt can access this COM object.

Share this post


Link to post
Share on other sites

Thanks for the reply's. I wound up just cheating :mellow:

CODE
#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#include <File.au3>

#include <Array.au3>

Dim $File

Opt('MustDeclareVars', 1)

OSDetect()

Func OSDetect()

Local $msg, $button_1, $MachineName, $name

GUICreate("OS Deploy", 300, 125, 0, 0) ; will create a dialog box that when displayed is centered

GUICtrlCreateLabel("Enter Machine Name:", 20, 10, 170, 40) ; first cell 70 width

$MachineName = GUICtrlCreateInput("", 0, 35, 300, 20)

GUICtrlSetState(-1, $GUI_DROPACCEPTED)

$button_1 = GUICtrlCreateButton("Okay", 170, 65, 120, 40)

GUISetState()

; Run the GUI until the dialog is closed

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $button_1

$name = GUICtrlRead($MachineName)

If FileExists(@ScriptDir & "\MachineName.vbs") Then

FileDelete (@ScriptDir & "\MachineName.vbs")

EndIf

_FileCreate (@ScriptDir & "\MachineName.vbs")

$File = FileOpen (@ScriptDir & "\MachineName.vbs", 2)

FileWriteLine($File, "set env = CreateObject(""Microsoft.SMS.TSEnvironment"")")

FileWriteLine($File, "env(""OSDComputerName"") = " & """" & $name &"""")

FileClose($file)

RunWait(@ComSpec & " /c " & "MachineName.vbs")

ExitLoop

EndSelect

WEnd

EndFunc

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
Sign in to follow this  
Followers 0