Jump to content

incorporate vbs into autoit


Recommended Posts

I have a vbs program that requires hard coding of Username, Password, Domain, Project, QCintegration(url), and the output location for the report. Then the complex vbs creates a report

I have this autoit code to prompt for the login username, password. I can modify it to also prompt for above other input attached is the vbs code which can have the values modified to reflect the values prompted for but I don't know how to actually "RUN" the vbs code from autoit

Opt("GUICoordMode", " 2")
$ret = _GUICreateLogin("Enter Credentials", "Enter the username and password", -1, -1, -1, -1, -1, 10000)
If @error Then
    MsgBox(0, "Error", "Error Returned: " & $ret & @CRLF & "Error Code: " & @error & @CRLF & "Extended: " & @extended)
Else
    MsgBox(0, "Credentails Returned", "Username: " & $ret[0] & @CRLF & "Password:  " & $ret[1])
EndIf

;===============================================================================
; Function Name:   _GUICreateLogin()
; Description:     Create a basic login box with Username, Password, and a prompt.
; Syntax:
; Parameter(s):    $hTitle - The title of the Form
;                  $hPrompt - The text prompt for the user [Optional] (maximum of 2 lines)
;                  $bBlank - The password or username can be blank. [optional]
;                            Default = False (Blanks are not allowed)
;                  $hWidth - Width of the form [optional] - default = 250
;                  $hHeight - Height of the form [optional] - default = 130
;                  $hLeft - X position [optional] - default = centered
;                  $hTop - Y position [optional] - default = centered
;                  $Timeout - The timeout of the form [optional - default = 0 (no timeout)
;                  $ShowError - Prompts are displayed to the user with timeout [optional]
; Requirement(s):  None
; Return Value(s): Success - Returns an array of 2 elements where
;                                        [0] = UserName
;                                        [1] = Password
;                  Failure - Sets @Error to 1 and
;                                 @Extended - 1 = Cancel/Exit Button Pressed
;                                           - 2 = Timed out
; Author(s):   Brett Francis (exodus.is.me@hotmail.com)
; Modification(s): GeoSoft
; Note(s): If $hPrompt is blank then the GUI height will be reduced by 30
; Example(s):
;===============================================================================

Func _GUICreateLogin($hTitle, $hPrompt = "", $bBlank = False, $hWidth = -1, $hHeight = -1, $hLeft = -1, $hTop = -1, $timeout = 0, $ShowError = 0)
    If Not $hTitle Then $hTitle = "Login" 
    $iGCM = Opt("GUICoordMode", 2);; Get the current value of GUICoordMode and set it to 2
    If StringRegExp($bBlank, "(?i)\s|default|-1") Then $bBlank = False
    If StringRegExp($hWidth, "(?i)\s|default|-1") Then $hWidth = 250
    If StringRegExp($hHeight, "(?i)\s|default|-1") Then $hHeight = 130
    If StringRegExp($hLeft, "(?i)\s|default|-1") Then $hLeft = (@DesktopWidth / 2) - ($hWidth / 2)
    If StringRegExp($hTop, "(?i)\s|default|-1") Then $hTop = (@DesktopHeight / 2) - ($hHeight / 2)
    If Not $hPrompt Then $hHeight -= 30;If $hPrompt is blank then resize the GUI.
    Local $retarr[2] = ["", ""], $Time = 0

    Local $gui = GUICreate($hTitle, $hWidth, $hHeight, $hLeft, $hTop)
    GUISetCoord(4, 0)
    If $hPrompt Then Local $Lbl_Prompt = GUICtrlCreateLabel($hPrompt, -1, 4, 201, 30)
    Local $Lbl_User = GUICtrlCreateLabel("Username:", -1, 4, 64, 17);44, 64, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    Local $username = GUICtrlCreateInput('', 8, -1, $hWidth - 81, 21)
    GUICtrlCreateLabel("Password:", -($hWidth - 8), 4, 65, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    Local $password = GUICtrlCreateInput('', 8, -1, $hWidth - 81, 21, 32);, $ES_PASSWORD)
    GUISetCoord(($hWidth / 2) - 85, $hHeight - 34)
    Local $Btn_OK = GUICtrlCreateButton("&OK", -1, -1, 75, 25)
    Local $Btn_Cancel = GUICtrlCreateButton("&Cancel", 20, -1, 75, 25)
    GUICtrlSetState($Btn_OK, 512)
    GUISetState()
    If $timeout Then $Time = TimerInit()
    While 1
        $Msg = GUIGetMsg()
        Local $sUser = GUICtrlRead($username)
        Local $sPass = GUICtrlRead($password)
        If ($Time And TimerDiff($Time) >= $timeout) And ($sUser = "" And $sPass = "") Then
            $Status = 2
            ExitLoop
        EndIf
        Select
            Case $Msg = -3
                $Status = 0
                ExitLoop
            Case $Msg = $Btn_OK
                If $bBlank And ($sUser = "" Or $sPass = "") Then
                    $Status = 1
                    ExitLoop
                Else
                    If $sUser <> "" And $sPass <> "" Then
                        $Status = 1
                        ExitLoop
                    Else
                        Select
                            Case $sUser = "" And $sPass = ""
                                If $ShowError = 1 Then MsgBox(16, "Error!", "Username and Password cannot be blank!")
                            Case $sPass = ""
                                If $ShowError = 1 Then MsgBox(16, "Error!", "Password cannot be blank!")
                                GUICtrlSetState($password, 256)
                            Case $sUser = ""
                                If $ShowError = 1 Then MsgBox(16, "Error!", "Username cannot be blank!")
                                GUICtrlSetState($username, 256)
                        EndSelect
                    EndIf
                EndIf
            Case $Msg = $Btn_Cancel
                $Status = 0
                ExitLoop
            Case $timeout And TimerDiff($Time) >= $timeout; And $timeout
                If $bBlank And ($sUser = "" Or $sPass = "") Then
                    $Status = 2
                    ExitLoop
                Else
                    ;$time = TimerInit()
                    Select
                        Case $sUser = "" And $sPass = ""
                            If $timeout Then $Time = TimerInit()
                            If $ShowError = 1 Then MsgBox(16, "Error!", "Username and Password cannot be blank!")
                        Case $sPass = ""
                            If $timeout Then $Time = TimerInit()
                            If $ShowError = 1 Then
                                MsgBox(16, "Error!", "Password cannot be blank!")
                                GUICtrlSetState($password, 256)
                            EndIf
                        Case $sUser = ""
                            $Time = TimerInit()
                            If $ShowError = 1 Then
                                MsgBox(16, "Error!", "Username cannot be blank!")
                                GUICtrlSetState($username, 256)
                            EndIf
                            ;Case ($Timeout AND TimerDiff($time) >= $timeout) AND ($sUser = "" OR $sPass = "")
                            ;$status = 2
                            ;ExitLoop
                        Case Else
                            If $sUser <> "" And $sPass <> "" Then
                                $Status = 3
                                ;If $Timeout AND TimerDiff($time) >= $timeout Then $Status = 2
                                ExitLoop
                            EndIf
                    EndSelect
                EndIf
        EndSelect
    WEnd
    Local $eMsg = ""
    Switch $Status
        Case 0, 2
            $err = 1;0
            $ext = 1;Cancel/Exit Button Pressed
            $eMsg = "Cancel/Exit Button Pressed" 
            If $Status = 2 Then $ext = 2;Timed Out
            If $ext = 2 Then $eMsg = "Timed Out" 
        Case Else;1, 3
            $retarr[0] = $sUser
            $retarr[1] = $sPass
            $err = 0;1
            $ext = 0
            If $Status = 3 Then $ext = 1;Username Fields Not Blank, Timeout reached
    EndSwitch
    GUIDelete($gui)
    Opt("GUICoordMode", $iGCM);Reset the GUICoordMode to what it started as.
    If $eMsg Then Return SetError($err, $ext, $eMsg)
    Return $retarr
EndFunc   ;==>_GUICreateLogin
Link to comment
Share on other sites

have u tried run / shellexecute.

just in case u dont have vbs files automatically configured to be run by windows script host (WScript.exe) then u might want to try cscript.exe "VBSFILENAME" which runs from command line. i.e., use comspec /c cscript.exe vbsfile it should work..

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...