Jump to content
Sign in to follow this  
kris00l

pass and return value from autoit exe

Recommended Posts

kris00l

I need to run a AutoIT exe within VBScript to pass and get value from it meaning:

I have AutoIT function with accepts parameters to create two radio buttons with captions value being parameters passed and return radio button selected caption. I have created Exe and calling this exe in Vbscript as

return = ObjShell.Run("cmd /c " & pathexefilename & " Radio1Value Radio2Value")

If return = "Radio1Value" Then

' do something

else

' do something

end if

AutoIT script:

Func ($Option1, $Option2)

;i'm not posting all the script details here but

case $msg = $Radio1

$RadioSel = $option1

case $msg = $Radio2

$RadioSel = $option2

case $msg = $OK_Btn

Return $RadioSel

EndFunc

Edited by kris00l

Share this post


Link to post
Share on other sites
stormbreaker

See Exit() function in help-file. Now, you could do the following:

1. If someone selects radio 1 then Exit(1)

2. If someone selecs radio 2 then Exit(2)

3. Catch the exit return code with VBS.


----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Share this post


Link to post
Share on other sites
kris00l

1. why not function return the value?

2. Error $cmdline

Here's complete code:

<job id="Z-Test">
<script language="VBScript">
 Set objShell = CreateObject("Wscript.Shell")
OSMig = ObjShell.Run("cmd /c C:UsersAdministratorDesktoptest.exe ""Are you migrating XP 32bit to XP 32bit?"" ""Are you migrating XP 32bit to Win 7 32bit?""")
If OSMig = "Are you migrating XP 32bit to XP 32bit?" Then
 Msgbox "migrating XP 32bit to XP 32bit"
Else
 Msgbox "migrating XP 32bit to Win 7 32bit"
End If
</script>
</job>

AutoIT Script - compiled to EXE as Test.exe

#include <GUIConstantsEx.au3>

$Return = CreateWindowOptions($CmdLine[1], $CmdLine[2]) ; errors here why

Func CreateWindowOptions($Option1, $Option2)
 ;Initialize variables
 Local $GUIWidth = 300, $GUIHeight = 250
 Local $Edit_1, $OK_Btn, $Cancel_Btn, $msg
 Local $RadioSel
 #forceref $Edit_1
 ;Create window
 GUICreate("New GUI", $GUIWidth, $GUIHeight)
$Radio1 = GUICtrlCreateRadio($Option1, 96, 64, 105, 41)
$Radio2 = GUICtrlCreateRadio($Option2, 96, 112, 73, 25)
 ;Create an "OK" button
$OK_Btn = GUICtrlCreateButton("OK", 72, 152, 105, 33)
 ;Show window/Make the window visible
 GUISetState(@SW_SHOW)
 ;Loop until:
 ;- user presses Esc
 ;- user presses Alt+F4
 ;- user clicks the close button
 While 1
  ;After every loop check if the user clicked something in the GUI window
  $msg = GUIGetMsg()
  Select
   ;Check if user clicked on the close button
   Case $msg = $GUI_EVENT_CLOSE
      Return $RadioSel
      ;Destroy the GUI including the controls
      GUIDelete()
      ;Exit the script
      Exit
    ;Check if user clicked on the "OK" button
   Case $msg = $OK_Btn
    MsgBox(64, "New GUI", "You clicked on the OK button! - " & $RadioSel)
    Return $RadioSel
;Destroy the GUI including the controls
      GUIDelete()
    ;Exit the script
    Exit

   Case $msg = $Radio1
      $RadioSel = $Option1

   case $msg = $Radio2
    $RadioSel = $Option2
  EndSelect
 WEnd
EndFunc   ;==>_Main
Edited by Melba23
Added code tags

Share this post


Link to post
Share on other sites
Melba23

kris00l,

When you post code please use Code tags - put [autoit] before and [/autoit] after your posted code. Then you get the scrolling box you can now see in your post above. :)

M23


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

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
kris00l

Error I figured it out.

You need to use $CmdLine[0] in the code.

So:

If $CmdLine[0] > 0 Then

$Return = CreateWindowOptions($CmdLine[1], $CmdLine[2])

EndIf

Share this post


Link to post
Share on other sites
kris00l

kris00l,

When you post code please use Code tags - put

before and
after your posted code. Then you get the scrolling box you can now see in your post above. :)

M23

I'm new here :bye:

I also noticed that I cannot edit my post after few mins. Is there a specific reason its locked?

Thanks

Edited by kris00l

Share this post


Link to post
Share on other sites
Melba23

kris00l,

After you have 5 posts, you get full "Edit" permissions - so be patient. ;)

M23


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

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

×