Sign in to follow this  
Followers 0
joeloyzaga

incorporate vbs into autoit script

23 posts in this topic

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

I have a login script in autoit and then I want to call vbs functions - so assuming I've got username and password how do you call "vbsfunc(username,password)". this function is defined in vbs and I would like to give it the parameters from the autoit gui and then run the vbs code (I assume I would use ScriptControl)

Any help would be appreciated - an example would be priceless

Share this post


Link to post
Share on other sites



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

I have a login script in autoit and then I want to call vbs functions - so assuming I've got username and password how do you call "vbsfunc(username,password)". this function is defined in vbs and I would like to give it the parameters from the autoit gui and then run the vbs code (I assume I would use ScriptControl)

Any help would be appreciated - an example would be priceless

Search the forum for ScriptControl. There are several examples already posted.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Search the forum for ScriptControl. There are several examples already posted.

:)

I have but they don't show how to interact with vbs

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I have but they don't show how to interact with vbs

I guess I'm not completely understanding you. Can you modify the original VBScript or not? On re-reading the OP, you seem to want to have AutoIt call one VBScript function with options, which in turn calls the original VBScript.

Maybe this will help. It's a demo derived from one posted earlier by DaleHohm:

Global $Vbs, $sCode, $sRET

$sCode = 'Function RegexMatches(sPattern, sString)' & _
        @LF & ' Dim oRegEx, oMatch, oMatches, RetStr' & _ ; Create variables.
        @LF & ' Set oRegEx = New RegExp' & _ ; Create regular expression.
        @LF & ' oRegEx.Pattern = sPattern' & _ ; Set pattern.
        @LF & ' oRegEx.IgnoreCase = True' & _ ; Set case sensitivity.
        @LF & ' oRegEx.Global = True' & _ ; Set Global option.
        @LF & ' Set oMatches = oRegEx.Execute(sString)' & _ ; Execute the search test.
        @LF & ' For Each oMatch in oMatches' & _
        @LF & '     RetStr = RetStr & "Match found at position "' & _
        @LF & '     RetStr = RetStr & oMatch.FirstIndex & vbCRLF' & _
        @LF & '     RetStr = RetStr & "Match Value is "' & _
        @LF & '     RetStr = RetStr & oMatch.Value & "." & vbCRLF & vbCRLF' & _
        @LF & ' Next' & _
        @LF & ' RegexMatches = RetStr' & _
        @LF & 'End Function' & _
        @LF

$Vbs = ObjCreate('ScriptControl')
If @error Then
    MsgBox(16, 'Error', 'Error creating MSScriptControl.ScriptControl')
    Exit
EndIf

$Vbs.Language = 'VBScript'

$Vbs.AddCode($sCode)

$sRET = $Vbs.Run('RegexMatches', '\d+', 'ABC123DEF')

ConsoleWrite("$sRET = " & $sRET & @LF)

:)

P.S. Here is a simpler example that seems to go more directly at what you were trying to do:

Global $Vbs, $sCode, $sRET

$sCode = 'Function LoginValues(sUserInput, sPassInput)' & _
        @LF & '  Dim RetStr' & _
        @LF & '  RetStr = "Login values were:" & vbCRLF' & _
        @LF & '  RetStr = RetStr & "User name = " & sUserInput & vbCRLF' & _
        @LF & '  RetStr = RetStr & "Password = " & sPassInput & vbCRLF' & _
        @LF & '  LoginValues = RetStr' & _
        @LF & 'End Function' & @LF

$Vbs = ObjCreate('ScriptControl')
If @error Then
    MsgBox(16, 'Error', 'Error creating ScriptControl')
    Exit
EndIf

$Vbs.Language = 'VBScript'

$Vbs.AddCode($sCode)

$sRET = $Vbs.Run('LoginValues', 'My_User_Name', 'My_Password')

ConsoleWrite("$sRET = " & $sRET & @LF)

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Maybe you can convert the VBS to AutoIt?

Other solution would be to modify the vbs to ask for the data.

Share this post


Link to post
Share on other sites

You can use autoit to prompt for auth values and then create the vbs script line by line (plugging in auth values) by using FileAppend, then you can 'run' the vbscript and finally delete it so the auth values aren't laying around on disk.

You can use sed for windows to help create the command to create the vbs script

http://gnuwin32.sourceforge.net/packages/sed.htm

type vbscript |sed -e "s/^Option/FileAppend, Option/g" -e "s/$/\\\n/g" -e "s/$/,vbscriptname.vbs/g" -e "s/\\\/zZzZ/g" -e "s/zZ/\\\/g" > boo.aut

Share this post


Link to post
Share on other sites

tried running your code (first one and got error)

I guess I'm not completely understanding you. Can you modify the original VBScript or not? On re-reading the OP, you seem to want to have AutoIt call one VBScript function with options, which in turn calls the original VBScript.

Maybe this will help. It's a demo derived from one posted earlier by DaleHohm:

Global $Vbs, $sCode, $sRET

$sCode = 'Function RegexMatches(sPattern, sString)' & _
        @LF & ' Dim oRegEx, oMatch, oMatches, RetStr' & _ ; Create variables.
        @LF & ' Set oRegEx = New RegExp' & _ ; Create regular expression.
        @LF & ' oRegEx.Pattern = sPattern' & _ ; Set pattern.
        @LF & ' oRegEx.IgnoreCase = True' & _ ; Set case sensitivity.
        @LF & ' oRegEx.Global = True' & _ ; Set Global option.
        @LF & ' Set oMatches = oRegEx.Execute(sString)' & _ ; Execute the search test.
        @LF & ' For Each oMatch in oMatches' & _
        @LF & '     RetStr = RetStr & "Match found at position "' & _
        @LF & '     RetStr = RetStr & oMatch.FirstIndex & vbCRLF' & _
        @LF & '     RetStr = RetStr & "Match Value is "' & _
        @LF & '     RetStr = RetStr & oMatch.Value & "." & vbCRLF & vbCRLF' & _
        @LF & ' Next' & _
        @LF & ' RegexMatches = RetStr' & _
        @LF & 'End Function' & _
        @LF

$Vbs = ObjCreate('ScriptControl')
If @error Then
    MsgBox(16, 'Error', 'Error creating MSScriptControl.ScriptControl')
    Exit
EndIf

$Vbs.Language = 'VBScript'

$Vbs.AddCode($sCode)

$sRET = $Vbs.Run('RegexMatches', '\d+', 'ABC123DEF')

ConsoleWrite("$sRET = " & $sRET & @LF)

:)

P.S. Here is a simpler example that seems to go more directly at what you were trying to do:

Global $Vbs, $sCode, $sRET

$sCode = 'Function LoginValues(sUserInput, sPassInput)' & _
        @LF & '  Dim RetStr' & _
        @LF & '  RetStr = "Login values were:" & vbCRLF' & _
        @LF & '  RetStr = RetStr & "User name = " & sUserInput & vbCRLF' & _
        @LF & '  RetStr = RetStr & "Password = " & sPassInput & vbCRLF' & _
        @LF & '  LoginValues = RetStr' & _
        @LF & 'End Function' & @LF

$Vbs = ObjCreate('ScriptControl')
If @error Then
    MsgBox(16, 'Error', 'Error creating ScriptControl')
    Exit
EndIf

$Vbs.Language = 'VBScript'

$Vbs.AddCode($sCode)

$sRET = $Vbs.Run('LoginValues', 'My_User_Name', 'My_Password')

ConsoleWrite("$sRET = " & $sRET & @LF)

:)

Share this post


Link to post
Share on other sites

lets make it easier

I want to run an autoit script that I have to get the username and login.

Then using the input from this (username, password) to run a a vbs script that accepts 2 input parameters - username, password) and then end

can I get an example for this?

I guess I'm not completely understanding you. Can you modify the original VBScript or not? On re-reading the OP, you seem to want to have AutoIt call one VBScript function with options, which in turn calls the original VBScript.

Maybe this will help. It's a demo derived from one posted earlier by DaleHohm:

Global $Vbs, $sCode, $sRET

$sCode = 'Function RegexMatches(sPattern, sString)' & _
        @LF & ' Dim oRegEx, oMatch, oMatches, RetStr' & _ ; Create variables.
        @LF & ' Set oRegEx = New RegExp' & _ ; Create regular expression.
        @LF & ' oRegEx.Pattern = sPattern' & _ ; Set pattern.
        @LF & ' oRegEx.IgnoreCase = True' & _ ; Set case sensitivity.
        @LF & ' oRegEx.Global = True' & _ ; Set Global option.
        @LF & ' Set oMatches = oRegEx.Execute(sString)' & _ ; Execute the search test.
        @LF & ' For Each oMatch in oMatches' & _
        @LF & '     RetStr = RetStr & "Match found at position "' & _
        @LF & '     RetStr = RetStr & oMatch.FirstIndex & vbCRLF' & _
        @LF & '     RetStr = RetStr & "Match Value is "' & _
        @LF & '     RetStr = RetStr & oMatch.Value & "." & vbCRLF & vbCRLF' & _
        @LF & ' Next' & _
        @LF & ' RegexMatches = RetStr' & _
        @LF & 'End Function' & _
        @LF

$Vbs = ObjCreate('ScriptControl')
If @error Then
    MsgBox(16, 'Error', 'Error creating MSScriptControl.ScriptControl')
    Exit
EndIf

$Vbs.Language = 'VBScript'

$Vbs.AddCode($sCode)

$sRET = $Vbs.Run('RegexMatches', '\d+', 'ABC123DEF')

ConsoleWrite("$sRET = " & $sRET & @LF)

:)

P.S. Here is a simpler example that seems to go more directly at what you were trying to do:

Global $Vbs, $sCode, $sRET

$sCode = 'Function LoginValues(sUserInput, sPassInput)' & _
        @LF & '  Dim RetStr' & _
        @LF & '  RetStr = "Login values were:" & vbCRLF' & _
        @LF & '  RetStr = RetStr & "User name = " & sUserInput & vbCRLF' & _
        @LF & '  RetStr = RetStr & "Password = " & sPassInput & vbCRLF' & _
        @LF & '  LoginValues = RetStr' & _
        @LF & 'End Function' & @LF

$Vbs = ObjCreate('ScriptControl')
If @error Then
    MsgBox(16, 'Error', 'Error creating ScriptControl')
    Exit
EndIf

$Vbs.Language = 'VBScript'

$Vbs.AddCode($sCode)

$sRET = $Vbs.Run('LoginValues', 'My_User_Name', 'My_Password')

ConsoleWrite("$sRET = " & $sRET & @LF)

:)

Share this post


Link to post
Share on other sites

lets make it easier

I want to run an autoit script that I have to get the username and login.

Then using the input from this (username, password) to run a a vbs script that accepts 2 input parameters - username, password) and then end

can I get an example for this?

So what I have here is the latest "play" script - I'm using the input fromn the login script to call a vbs script but the call does not seem to work - which somewhat stumps me!!!!!

any takers?

#include <GUIConstants.Au3>
#include <Misc.Au3>
Opt('GUIOnEventMode', '1')
Opt('WinTitleMatchMode', '2')
Global $Username = 'Username'
Global $Password = 'Password'
Global $Secret_Text = 'AutoIt Rocks!'
Global $Void = False
Global $Vbs, $sCode, $sRET
$Vbs = ObjCreate('ScriptControl')
$GUI = GUICreate('Login Form (Example)', '185', '88', '-1', '-1', '-1', '128')
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')
GUICtrlCreateLabel('Username : ', '5', '6', '100', '20')
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
GUICtrlSetColor('-1', '0x000FF')
$Input_Username = GUICtrlCreateInput('', '80', '5', '100', '20', '1')
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
GUICtrlCreateLabel('Password : ', '7', '35', '100', '20')
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
GUICtrlSetColor('-1', '0x000FF')
$Input_Password = GUICtrlCreateInput('', '80', '34', '100', '20', BitOR('0x0020', '1'))
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
$Login_Button = GUICtrlCreateLabel('Account Login', '50', '62', '84', '16')
GUICtrlSetBkColor('-1', $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetOnEvent('-1', '_Login')
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
GUICtrlSetColor('-1', '0xFFF000')
GUISetState(@SW_SHOW)

While '1'
    Sleep('15')
    If _IsPressed('0D') And WinActive($GUI) And _Check() = '1' Then _Login()
WEnd

Func _Check()
    $Focus = ControlGetFocus($GUI)
    If $Focus = 'Edit1' Or 'Edit2' Then Return '1'
EndFunc

Func _Login()
    $1 = GUICtrlRead($Input_Username) ; Inputed Username
    $2 = GUICtrlRead($Input_Password) ; Inputed Password
    ; Check
    If $1 = $Username And $2 =  $Password Then 
        MsgBox('0', 'Secret Text!', 'Secret Text : ' & $Secret_Text, '0')
        $sRET = $Vbs.Run('LoginValues', $1, $2)
    ElseIf $1 = $Username And $2 <> $Password Then 
        MsgBox('16', 'Error Code 01', 'Incorrect Password, Please Try Again', '0')
    ElseIf $1 <> $Username And $2 =  $Password Then 
        MsgBox('16', 'Error Code 02', 'Incorrect Username, Please Try Again', '0')
    ElseIf $2 <> $Username And $2 <> $Password Then 
        MsgBox('16', 'Error Code 03', 'Incorrect Username And Password, Please Try Again', '0')
    EndIf 
    Sleep('500')
EndFunc

Func _Exit()
    Exit
EndFunc
;Global $Vbs, $sCode, $sRET

$sCode = 'Function LoginValues(sUserInput, sPassInput)' & _
        @LF & '  Dim RetStr' & _
        @LF & '  RetStr = "Login values were:" & vbCRLF' & _
        @LF & '  RetStr = RetStr & "User name = " & sUserInput & vbCRLF' & _
        @LF & '  RetStr = RetStr & "Password = " & sPassInput & vbCRLF' & _
        @LF & '  LoginValues = RetStr' & _
        @LF & 'End Function' & @LF

$Vbs = ObjCreate('ScriptControl')
If @error Then
    MsgBox(16, 'Error', 'Error creating ScriptControl')
    Exit
EndIf

$Vbs.Language = 'VBScript'

$Vbs.AddCode($sCode)

$sRET = $Vbs.Run('LoginValues', 'My_User_Name', 'My_Password')

ConsoleWrite("$sRET = " & $sRET & @LF)

Share this post


Link to post
Share on other sites

lets make it easier

I want to run an autoit script that I have to get the username and login.

Then using the input from this (username, password) to run a a vbs script that accepts 2 input parameters - username, password) and then end

can I get an example for this?

So what I have here is the latest "play" script - I'm using the input fromn the login script to call a vbs script but the call does not seem to work - which somewhat stumps me!!!!!

any takers?

#include <GUIConstants.Au3>
#include <Misc.Au3>
Opt('GUIOnEventMode', '1')
Opt('WinTitleMatchMode', '2')
Global $Username = 'Username'
Global $Password = 'Password'
Global $Secret_Text = 'AutoIt Rocks!'
Global $Void = False
Global $Vbs, $sCode, $sRET
$Vbs = ObjCreate('ScriptControl')
$GUI = GUICreate('Login Form (Example)', '185', '88', '-1', '-1', '-1', '128')
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')
GUICtrlCreateLabel('Username : ', '5', '6', '100', '20')
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
GUICtrlSetColor('-1', '0x000FF')
$Input_Username = GUICtrlCreateInput('', '80', '5', '100', '20', '1')
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
GUICtrlCreateLabel('Password : ', '7', '35', '100', '20')
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
GUICtrlSetColor('-1', '0x000FF')
$Input_Password = GUICtrlCreateInput('', '80', '34', '100', '20', BitOR('0x0020', '1'))
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
$Login_Button = GUICtrlCreateLabel('Account Login', '50', '62', '84', '16')
GUICtrlSetBkColor('-1', $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetOnEvent('-1', '_Login')
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
GUICtrlSetColor('-1', '0xFFF000')
GUISetState(@SW_SHOW)

While '1'
    Sleep('15')
    If _IsPressed('0D') And WinActive($GUI) And _Check() = '1' Then _Login()
WEnd

Func _Check()
    $Focus = ControlGetFocus($GUI)
    If $Focus = 'Edit1' Or 'Edit2' Then Return '1'
EndFunc

Func _Login()
    $1 = GUICtrlRead($Input_Username) ; Inputed Username
    $2 = GUICtrlRead($Input_Password) ; Inputed Password
    ; Check
    If $1 = $Username And $2 =  $Password Then 
        MsgBox('0', 'Secret Text!', 'Secret Text : ' & $Secret_Text, '0')
        $sRET = $Vbs.Run('LoginValues', $1, $2)
    ElseIf $1 = $Username And $2 <> $Password Then 
        MsgBox('16', 'Error Code 01', 'Incorrect Password, Please Try Again', '0')
    ElseIf $1 <> $Username And $2 =  $Password Then 
        MsgBox('16', 'Error Code 02', 'Incorrect Username, Please Try Again', '0')
    ElseIf $2 <> $Username And $2 <> $Password Then 
        MsgBox('16', 'Error Code 03', 'Incorrect Username And Password, Please Try Again', '0')
    EndIf 
    Sleep('500')
EndFunc

Func _Exit()
    Exit
EndFunc
;Global $Vbs, $sCode, $sRET

$sCode = 'Function LoginValues(sUserInput, sPassInput)' & _
        @LF & '  Dim RetStr' & _
        @LF & '  RetStr = "Login values were:" & vbCRLF' & _
        @LF & '  RetStr = RetStr & "User name = " & sUserInput & vbCRLF' & _
        @LF & '  RetStr = RetStr & "Password = " & sPassInput & vbCRLF' & _
        @LF & '  LoginValues = RetStr' & _
        @LF & 'End Function' & @LF

$Vbs = ObjCreate('ScriptControl')
If @error Then
    MsgBox(16, 'Error', 'Error creating ScriptControl')
    Exit
EndIf

$Vbs.Language = 'VBScript'

$Vbs.AddCode($sCode)

$sRET = $Vbs.Run('LoginValues', 'My_User_Name', 'My_Password')

ConsoleWrite("$sRET = " & $sRET & @LF)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

So what I have here is the latest "play" script - I'm using the input fromn the login script to call a vbs script but the call does not seem to work - which somewhat stumps me!!!!!

any takers?

#include <GUIConstants.Au3>
#include <Misc.Au3>
Opt('GUIOnEventMode', '1')
Opt('WinTitleMatchMode', '2')
Global $Username = 'Username'
Global $Password = 'Password'
Global $Secret_Text = 'AutoIt Rocks!'
Global $Void = False
Global $Vbs, $sCode, $sRET
$Vbs = ObjCreate('ScriptControl')
$GUI = GUICreate('Login Form (Example)', '185', '88', '-1', '-1', '-1', '128')
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')
GUICtrlCreateLabel('Username : ', '5', '6', '100', '20')
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
GUICtrlSetColor('-1', '0x000FF')
$Input_Username = GUICtrlCreateInput('', '80', '5', '100', '20', '1')
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
GUICtrlCreateLabel('Password : ', '7', '35', '100', '20')
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
GUICtrlSetColor('-1', '0x000FF')
$Input_Password = GUICtrlCreateInput('', '80', '34', '100', '20', BitOR('0x0020', '1'))
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
$Login_Button = GUICtrlCreateLabel('Account Login', '50', '62', '84', '16')
GUICtrlSetBkColor('-1', $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetOnEvent('-1', '_Login')
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
GUICtrlSetColor('-1', '0xFFF000')
GUISetState(@SW_SHOW)

While '1'
    Sleep('15')
    If _IsPressed('0D') And WinActive($GUI) And _Check() = '1' Then _Login()
WEnd

Func _Check()
    $Focus = ControlGetFocus($GUI)
    If $Focus = 'Edit1' Or 'Edit2' Then Return '1'
EndFunc

Func _Login()
    $1 = GUICtrlRead($Input_Username) ; Inputed Username
    $2 = GUICtrlRead($Input_Password) ; Inputed Password
    ; Check
    If $1 = $Username And $2 =  $Password Then 
        MsgBox('0', 'Secret Text!', 'Secret Text : ' & $Secret_Text, '0')
        $sRET = $Vbs.Run('LoginValues', $1, $2)
    ElseIf $1 = $Username And $2 <> $Password Then 
        MsgBox('16', 'Error Code 01', 'Incorrect Password, Please Try Again', '0')
    ElseIf $1 <> $Username And $2 =  $Password Then 
        MsgBox('16', 'Error Code 02', 'Incorrect Username, Please Try Again', '0')
    ElseIf $2 <> $Username And $2 <> $Password Then 
        MsgBox('16', 'Error Code 03', 'Incorrect Username And Password, Please Try Again', '0')
    EndIf 
    Sleep('500')
EndFunc

Func _Exit()
    Exit
EndFunc
;Global $Vbs, $sCode, $sRET

$sCode = 'Function LoginValues(sUserInput, sPassInput)' & _
        @LF & '  Dim RetStr' & _
        @LF & '  RetStr = "Login values were:" & vbCRLF' & _
        @LF & '  RetStr = RetStr & "User name = " & sUserInput & vbCRLF' & _
        @LF & '  RetStr = RetStr & "Password = " & sPassInput & vbCRLF' & _
        @LF & '  LoginValues = RetStr' & _
        @LF & 'End Function' & @LF

$Vbs = ObjCreate('ScriptControl')
If @error Then
    MsgBox(16, 'Error', 'Error creating ScriptControl')
    Exit
EndIf

$Vbs.Language = 'VBScript'

$Vbs.AddCode($sCode)

$sRET = $Vbs.Run('LoginValues', 'My_User_Name', 'My_Password')

ConsoleWrite("$sRET = " & $sRET & @LF)
You never execute the code that adds the VBScript lines to the ScriptControl object. Change your _Login() this way:
Func _Login()
    $1 = GUICtrlRead($Input_Username) ; Inputed Username
    $2 = GUICtrlRead($Input_Password) ; Inputed Password
    ; Check
    If $1 = $Username And $2 = $Password Then
        MsgBox('0', 'Secret Text!', 'Secret Text : ' & $Secret_Text, '0')
        $sCode = 'Function LoginValues(sUserInput, sPassInput)' & _
                @LF & '  Dim RetStr' & _
                @LF & '  RetStr = "Login values were:" & vbCRLF' & _
                @LF & '  RetStr = RetStr & "User name = " & sUserInput & vbCRLF' & _
                @LF & '  RetStr = RetStr & "Password = " & sPassInput & vbCRLF' & _
                @LF & '  LoginValues = RetStr' & _
                @LF & 'End Function' & @LF

        $Vbs = ObjCreate('ScriptControl')
        If @error Then
            MsgBox(16, 'Error', 'Error creating ScriptControl')
            Exit
        EndIf

        $Vbs.Language = 'VBScript'

        $Vbs.AddCode($sCode)

        $sRET = $Vbs.Run('LoginValues', $1, $2)

        ConsoleWrite("$sRET = " & $sRET & @LF)
    ElseIf $1 = $Username And $2 <> $Password Then
        MsgBox('16', 'Error Code 01', 'Incorrect Password, Please Try Again', '0')
    ElseIf $1 <> $Username And $2 = $Password Then
        MsgBox('16', 'Error Code 02', 'Incorrect Username, Please Try Again', '0')
    ElseIf $2 <> $Username And $2 <> $Password Then
        MsgBox('16', 'Error Code 03', 'Incorrect Username And Password, Please Try Again', '0')
    EndIf
    Sleep('500')
EndFunc   ;==>_Login

...and you should add a COM error handler, too.

>_<

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Add the ComErrorHandler to get more meaningful error descriptions.

I got this error when running it this way so added a language line:

### COM Error !  Number: 80020009   ScriptLine: 48   Description:The operation could not be completed because the script engine has not been initialized to a valid language.

Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
#include <GUIConstants.Au3>
#include <Misc.Au3>
Opt('GUIOnEventMode', '1')
Opt('WinTitleMatchMode', '2')
Global $Username = 'Username'
Global $Password = 'Password'
Global $Secret_Text = 'AutoIt Rocks!'
Global $Void = False
Global $Vbs, $sCode, $sRET
$Vbs = ObjCreate('ScriptControl')
$GUI = GUICreate('Login Form (Example)', '185', '88', '-1', '-1', '-1', '128')
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')
GUICtrlCreateLabel('Username : ', '5', '6', '100', '20')
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
GUICtrlSetColor('-1', '0x000FF')
$Input_Username = GUICtrlCreateInput('', '80', '5', '100', '20', '1')
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
GUICtrlCreateLabel('Password : ', '7', '35', '100', '20')
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
GUICtrlSetColor('-1', '0x000FF')
$Input_Password = GUICtrlCreateInput('', '80', '34', '100', '20', BitOR('0x0020', '1'))
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
$Login_Button = GUICtrlCreateLabel('Account Login', '50', '62', '84', '16')
GUICtrlSetBkColor('-1', $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetOnEvent('-1', '_Login')
GUICtrlSetFont('-1', '10', '', '', 'Microsoft Sans Serif')
GUICtrlSetColor('-1', '0xFFF000')
GUISetState(@SW_SHOW)

While '1'
    Sleep('15')
    If _IsPressed('0D') And WinActive($GUI) And _Check() = '1' Then _Login()
WEnd

Func _Check()
    $Focus = ControlGetFocus($GUI)
    If $Focus = 'Edit1' Or 'Edit2' Then Return '1'
EndFunc   ;==>_Check

Func _Login()
    $1 = GUICtrlRead($Input_Username) ; Inputed Username
    $2 = GUICtrlRead($Input_Password) ; Inputed Password
    ; Check
    If $1 = $Username And $2 = $Password Then
        MsgBox('0', 'Secret Text!', 'Secret Text : ' & $Secret_Text, '0')
        $Vbs.Language = 'VBScript'
        $sRET = $Vbs.Run('LoginValues', $1, $2)
    ElseIf $1 = $Username And $2 <> $Password Then
        MsgBox('16', 'Error Code 01', 'Incorrect Password, Please Try Again', '0')
    ElseIf $1 <> $Username And $2 = $Password Then
        MsgBox('16', 'Error Code 02', 'Incorrect Username, Please Try Again', '0')
    ElseIf $2 <> $Username And $2 <> $Password Then
        MsgBox('16', 'Error Code 03', 'Incorrect Username And Password, Please Try Again', '0')
    EndIf
    Sleep('500')
EndFunc   ;==>_Login

Func _Exit()
    Exit
EndFunc   ;==>_Exit
;Global $Vbs, $sCode, $sRET

$sCode = 'Function LoginValues(sUserInput, sPassInput)' & _
        @LF & '  Dim RetStr' & _
        @LF & '  RetStr = "Login values were:" & vbCRLF' & _
        @LF & '  RetStr = RetStr & "User name = " & sUserInput & vbCRLF' & _
        @LF & '  RetStr = RetStr & "Password = " & sPassInput & vbCRLF' & _
        @LF & '  LoginValues = RetStr' & _
        @LF & 'End Function' & @LF

$Vbs = ObjCreate('ScriptControl')
If @error Then
    MsgBox(16, 'Error', 'Error creating ScriptControl')
    Exit
EndIf

$Vbs.Language = 'VBScript'

$Vbs.AddCode($sCode)

$sRET = $Vbs.Run('LoginValues', 'My_User_Name', 'My_Password')

ConsoleWrite("$sRET = " & $sRET & @LF)


;
;
; Com Error Handler
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description, 3)
    ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)
    SetError(1); something to check for when this function returns
    Return
EndFunc   ;==>MyErrFunc

EDIT: I am sure PsaltyDS had the same idea about adding this ComErrorHandler >_<

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

EDIT: I am sure PsaltyDS had the same idea about adding this ComErrorHandler >_<

I am sure I don't know what you mean...

:(


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

You never execute the code that adds the VBScript lines to the ScriptControl object. Change your _Login() this way:

Func _Login()
    $1 = GUICtrlRead($Input_Username) ; Inputed Username
    $2 = GUICtrlRead($Input_Password) ; Inputed Password
    ; Check
    If $1 = $Username And $2 = $Password Then
        MsgBox('0', 'Secret Text!', 'Secret Text : ' & $Secret_Text, '0')
        $sCode = 'Function LoginValues(sUserInput, sPassInput)' & _
                @LF & '  Dim RetStr' & _
                @LF & '  RetStr = "Login values were:" & vbCRLF' & _
                @LF & '  RetStr = RetStr & "User name = " & sUserInput & vbCRLF' & _
                @LF & '  RetStr = RetStr & "Password = " & sPassInput & vbCRLF' & _
                @LF & '  LoginValues = RetStr' & _
                @LF & 'End Function' & @LF

        $Vbs = ObjCreate('ScriptControl')
        If @error Then
            MsgBox(16, 'Error', 'Error creating ScriptControl')
            Exit
        EndIf

        $Vbs.Language = 'VBScript'

        $Vbs.AddCode($sCode)

        $sRET = $Vbs.Run('LoginValues', $1, $2)

        ConsoleWrite("$sRET = " & $sRET & @LF)
    ElseIf $1 = $Username And $2 <> $Password Then
        MsgBox('16', 'Error Code 01', 'Incorrect Password, Please Try Again', '0')
    ElseIf $1 <> $Username And $2 = $Password Then
        MsgBox('16', 'Error Code 02', 'Incorrect Username, Please Try Again', '0')
    ElseIf $2 <> $Username And $2 <> $Password Then
        MsgBox('16', 'Error Code 03', 'Incorrect Username And Password, Please Try Again', '0')
    EndIf
    Sleep('500')
EndFunc   ;==>_Login

...and you should add a COM error handler, too.

>_<

So how would I run a vbs program with the username and password I have just received then - lets use this function in vbs -which outputs to the screen

function displaythis(uname,pword)

msgbox("username: " & uname & "password: " & pword)

End Function

Share this post


Link to post
Share on other sites

I dont get it . Why do you make it complicate ? Just add in the VBS script a prompt for user and password and use autoit to run the vbs.

Put in the vbs:

dim username
username=InputBox("Enter your username:")

Share this post


Link to post
Share on other sites

I dont get it . Why do you make it complicate ? Just add in the VBS script a prompt for user and password and use autoit to run the vbs.

Put in the vbs:

dim username
username=InputBox("Enter your username:")

Thats the problem - I don't know how to run it! how would autoit run this?

Share this post


Link to post
Share on other sites

just put the user and password prompt in the VBS file and use shellexecute to run the vbs file.

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

because this is the vbs program I'm trying to run

and I've been asked to prompt using a dialog box for username, password, use this and the url below to connect to QC using the QCConnection.Login CALL and use the resultant connection to get the domain and project (with this code from another vba prog)

Private Sub UserForm_Activate()

    If cbDomainList.ListCount > 0 Then Exit Sub ' meaning the form already initialized

On Error GoTo ErrorHandler:
    
    Dim domainArray() As String
    Dim i As Integer
    Dim domainName As String
    
    domainName = m_settings.ReadStringValue(INI_FILE_TD_SECTION, INI_FILE_DOMAIN_NAME)
    
    ' retrieve all the domains projects from the TDServer
    m_server.EnumDomains domainArray
    
    If UBound(domainArray) <= 0 Then Exit Sub
    
    For i = 1 To UBound(domainArray)
        cbDomainList.AddItem domainArray(i)
        If domainName = domainArray(i) Then
            cbDomainList.value = domainName
        End If
    Next i
    
    If cbDomainList.value = "" Then
        cbDomainList.value = domainArray(1) ' default
    End If
    
    Exit Sub
    
ErrorHandler:
    errObj.SetErrorObject Err.number, Err.source, Err.Description
    errObj.Log S_TS_DOMAIN_PROJECT, "UserForm_Initialize" ' log the error

End Sub

call this with the result from above "QCConnection.Connect sDomain, sProject" and then call the report/s below dependant on the 2 checkboxes for selection of which report types I want.

SO..... I thought I'd start it piecemeal - how to run QCConnection.Login using the values retrieved from an AUTIT login script

ALL these values I've been asked to retrieve using AUTOIT - I can't explain it any more than this

'Option Explicit 
Const xlLeft = -4131 
Const xlRight = -4152 
Const xlCenter = -4108 
Const xlGeneral = 1 
Dim QCConnection
Dim oExcel
Set QCConnection = CreateObject("TDApiOle80.TDConnection")
Set oExcel = CreateObject("excel.application")
'oExcel.WindowState = "Minimized" 

Var = oExcel.Run ("'C:\HP-Export\Test-Case-Import1.xls'!Export to Quality Center")
'Varrun = Var(1) + "-"+Var(0) +"-"+ Var(2) +"-" + Var(3) + "|" + InputBox("Starting point.  Press OK to accept or type new start point. Include Header Row", _
'           "Check Point Restart", 2) + "|" +  InputBox("Ending point.  Press OK to accept or type new end  point.", "Check Point Restart", 0)
'Environment = Var(0)
'Scriptname = Var(1)
Uname = Var(4)
Passwd = Var(5)
'AUT = Var(2)
' Varfull(MyRow) = Varrun



Dim sUserName, sPassword
sUserName = Uname 
sPassword = Passwd


QCConnection.InitConnectionEx "http://qualitycenter.test.det.nsw.edu.au:8080/qcbin/" '<------------------- Change me.


QCConnection.Login sUserName, sPassword

If (QCConnection.LoggedIn <> True) Then
    MsgBox "QC User Authentication Failed"
    WScript.Quit
End If
KillExcel ()
'oExcel = nothing
Dim sDomain, sProject
sDomain = "LEARNING_MANAGEMENT_SYSTEMS"   '<-------------------- Change me.
sProject = "TBO_Service" '<-------------------------------- Change me.

QCConnection.Connect sDomain, sProject

If (QCConnection.Connected <> True) Then
    MsgBox "QC Project Failed to Connect to " & sProject
    WScript.Quit
End If

Call ExportTestCases("Subject\Regression") '<-------------------------------- Change me.
'Call ExportDefects()


QCConnection.Disconnect
QCConnection.Logout
QCConnection.ReleaseConnection 


'------------------------------------------------------


''
'Print all the Fields for the passed in object.
'
'@param:    objObject   Object that supports the Fields method.
'
'@return:               No return value.
Function PrintFields(objObject)
    Dim FieldsList, Field
    Set FieldsList = objObject.Fields
    
    For Each Field In FieldsList
        WScript.Echo Field
    Next
End Function



''
'Export test cases for the Test Lab node.
'
'@param:    strNodeByPath   String for the node path in Test Lab.
'
'@return:                   No return value.
Function ExportTestCases(strNodeByPath)
    Dim Excel, Sheet
    Set Excel = CreateObject("Excel.Application") 'Open Excel
    Excel.WorkBooks.Add() 'Add a new workbook
    'Get the first worksheet.
    Set Sheet = Excel.ActiveSheet
    
    Sheet.Name = "Tests"
    
    With Sheet.Range("A1:H1")
        .Font.Name = "Arial"
        .Font.FontStyle = "Bold"
        .Font.Size = 10
        .Font.Bold = True
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .Interior.ColorIndex = 15 'Light Grey
    End With
    
    Sheet.Cells(1, 1) = "Subject (Folder Name)"
    Sheet.Cells(1, 2) = "Test Name (Manual Test Plan Name)"
    Sheet.Cells(1, 3) = "Description"
    Sheet.Cells(1, 4) = "Designer (Owner)"
    Sheet.Cells(1, 5) = "Status"
    Sheet.Cells(1, 6) = "Step Name"
    Sheet.Cells(1, 7) = "Step Description(Action)"
    Sheet.Cells(1, 8) = "Expected Result"

    'Call PrintFields(TestFactory)  
    
    Dim TreeMgr, TestTree, TestFactory, TestList
    Set TreeMgr = QCConnection.TreeManager

    'Specify the folder path in TestPlan, all the tests under that folder will be exported.
    Set TestTree = TreeMgr.NodeByPath(strNodeByPath)
    Set TestFactory = TestTree.TestFactory
    Set TestList = TestFactory.NewList("") 'Get a list of all from node.

    'Specify Array to contain all nodes of subject tree.
    Dim NodesList()
    ReDim Preserve NodesList(0)
    'Assign root node of subject tree as NodeByPath node.
    NodesList(0) = TestTree.Path
    
    'Gets subnodes and return list in array NodesList
    Call GetNodesList(TestTree, NodesList)

    Dim Row, Node, TestCase
    Row = 2
    For Each Node In NodesList
        Set TestTree = TreeMgr.NodeByPath(Node)
        Set TestFactory = TestTree.TestFactory
        Set TestList = TestFactory.NewList("") 'Get a list of all from node.

        'Iterate through all the tests.
        For Each TestCase In TestList
            Dim DesignStepFactory, DesignStep, DesignStepList
            Set DesignStepFactory = TestCase.DesignStepFactory
            Set DesignStepList = DesignStepFactory.NewList("")
            
            If DesignStepList.Count = 0 Then
                'Save a specified set of fields.
                Sheet.Cells(Row, 1).Value = TestCase.Field("TS_SUBJECT").Path
                Sheet.Cells(Row, 2).Value = TestCase.Field("TS_NAME")
                Sheet.Cells(Row, 3).Value = stripHTML(TestCase.Field("TS_DESCRIPTION"))
                Sheet.Cells(Row, 4).Value = TestCase.Field("TS_RESPONSIBLE")
                Sheet.Cells(Row, 5).Value = TestCase.Field("TS_EXEC_STATUS")
                Row = Row + 1
            Else
                
                    'Save a specified set of fields.
                    Sheet.Cells(Row, 1).Value = TestCase.Field("TS_SUBJECT").Path
                    Sheet.Cells(Row, 2).Value = TestCase.Field("TS_NAME")
                    Sheet.Cells(Row, 3).Value = stripHTML(TestCase.Field("TS_DESCRIPTION"))
                    Sheet.Cells(Row, 4).Value = TestCase.Field("TS_RESPONSIBLE")
                    Sheet.Cells(Row, 5).Value = TestCase.Field("TS_EXEC_STATUS")
                   For Each DesignStep In DesignStepList  
                    'Save the specified design steps.
                    Sheet.Cells(Row, 6).Value = stripHTML(DesignStep.StepName)
                    Sheet.Cells(Row, 7).Value = stripHTML(DesignStep.StepDescription)
                    Sheet.Cells(Row, 8).Value = stripHTML(DesignStep.StepExpectedResult)
                    Row = Row + 1
                Next
            End If
        Next
    Next
    
    'Call PrintFields(DesignStepFactory)
    
    Excel.Columns.AutoFit
    
    'Set the Column width for the following columns.
    Excel.Columns("C").ColumnWidth = 80 'Description
    Excel.Columns("G").ColumnWidth = 80 'Step Description(Action)
    Excel.Columns("H").ColumnWidth = 80 'Expected Result
    
    'Set Auto Filter mode.
    If Not Sheet.AutoFilterMode Then
        Sheet.Range("A1").AutoFilter
    End If
    
    'Freeze first row.
    Sheet.Range("A2").Select
    Excel.Activewindow.FreezePanes = True   
    
    'Save the newly created workbook and close Excel.
    Excel.ActiveWorkbook.SaveAs("C:\" & sProject & "_TESTCASES.xls")
    Excel.Quit
    
    Set Excel = Nothing
    Set DesignStepList = Nothing
    Set DesignStepFactory = Nothing
    Set TestList = Nothing
    Set TestFactory = Nothing
    Set TestTree = Nothing  
    Set TreeMgr = Nothing
End Function



''
'Export all defects for the current project.
'
'@return:   No return value.
Function ExportDefects()
    Dim BugFactory, BugList
    Set BugFactory = QCConnection.BugFactory
    Set BugList = BugFactory.NewList("") 'Get a list of all the defects.

    Dim Excel, Sheet
    Set Excel = CreateObject("Excel.Application") 'Open Excel
    Excel.WorkBooks.Add() 'Add a new workbook
    'Get the first worksheet.
    Set Sheet = Excel.ActiveSheet
    
    Sheet.Name = "Defects"
    
    With Sheet.Range("A1:U1")
        .Font.Name = "Arial"
        .Font.FontStyle = "Bold"
        .Font.Size = 10
        .Font.Bold = True
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .Interior.ColorIndex = 15 'Light Grey
    End With
    
    Sheet.Cells(1, 1) = "DefectID"
    Sheet.Cells(1, 2) = "Status"
    Sheet.Cells(1, 3) = "Severity"
    Sheet.Cells(1, 4) = "Priority"
    Sheet.Cells(1, 5) = "Summary"
    Sheet.Cells(1, 6) = "Detected By"
    Sheet.Cells(1, 7) = "Found in Version"
    Sheet.Cells(1, 8) = "Found in Build"
    Sheet.Cells(1, 9) = "Detected on Date"
    Sheet.Cells(1, 10) = "Closing Date"
    Sheet.Cells(1, 11) = "Actual Fix Time(Days)"
    Sheet.Cells(1, 12) = "Type"
    Sheet.Cells(1, 13) = "Module"
    Sheet.Cells(1, 14) = "Fixed in Version"
    Sheet.Cells(1, 15) = "Fixed in Build"
    Sheet.Cells(1, 16) = "Tester Closing Date"
    Sheet.Cells(1, 17) = "Email"
    Sheet.Cells(1, 18) = "Submission Date"
    Sheet.Cells(1, 19) = "Business Impact"
    Sheet.Cells(1, 20) = "Subject"
    Sheet.Cells(1, 21) = "Assigned To"
    
    'Call PrintFields(BugFactory)   
    
    Dim Row, Bug
    Row = 2
    'Iterate through all the defects.
    For Each Bug In BugList
        'Save a specified set of fields.
        Sheet.Cells(Row, 1).Value = Bug.Field("BG_BUG_ID")
        Sheet.Cells(Row, 2).Value = Bug.Status
        Sheet.Cells(Row, 3).Value = Bug.Field("BG_SEVERITY")
        Sheet.Cells(Row, 4).Value = Bug.Priority
        Sheet.Cells(Row, 5).Value = Bug.Summary
        Sheet.Cells(Row, 6).Value = Bug.DetectedBy
        Sheet.Cells(Row, 7).Value = Bug.Field("BG_DETECTION_VERSION")
        Sheet.Cells(Row, 8).Value = Bug.Field("BG_USER_03")
        Sheet.Cells(Row, 9).Value = Bug.Field("BG_DETECTION_DATE") 
        Sheet.Cells(Row, 10).Value = Bug.Field("BG_CLOSING_DATE")
        Sheet.Cells(Row, 11).Value = Bug.Field("BG_ACTUAL_FIX_TIME")
        Sheet.Cells(Row, 12).Value = Bug.Field("BG_USER_01")
        Sheet.Cells(Row, 13).Value = Bug.Field("BG_USER_02")
        Sheet.Cells(Row, 14).Value = Bug.Field("BG_USER_06")
        Sheet.Cells(Row, 15).Value = Bug.Field("BG_USER_04")
        Sheet.Cells(Row, 16).Value = Bug.Field("BG_USER_05")
        Sheet.Cells(Row, 17).Value = Bug.Field("BG_USER_07")
        Sheet.Cells(Row, 18).Value = Bug.Field("BG_USER_08")
        Sheet.Cells(Row, 19).Value = Bug.Field("BG_USER_09")
        Sheet.Cells(Row, 20).Value = Bug.Field("BG_SUBJECT")
        Sheet.Cells(Row, 21).Value = Bug.AssignedTo
        Row = Row + 1
    Next
    
    Excel.Columns.AutoFit
    
    'Set the Column width for the following columns.
    Excel.Columns("C").ColumnWidth = 80 'Summary

    'Set Auto Filter mode.
    If Not Sheet.AutoFilterMode Then
        Sheet.Range("A1").AutoFilter
    End If
    
    'Freeze first row.
    Sheet.Range("A2").Select
    Excel.Activewindow.FreezePanes = True   
    
    'Save the newly created workbook and close Excel.
    Excel.ActiveWorkbook.SaveAs("C:\" & sProject & "_DEFECTS.xls")
    Excel.Quit
    
    Set Excel = Nothing
    Set BugList = Nothing
    Set BugFactory = Nothing
End Function



''
'Returns a NodesList array for all children of a given node of a tree.
'
'@param:    Node        Node in a Test Lab tree.
'
'@param:    NodesList   Array to store all children of a given node of a tree.
'
'@return:   No explicit return value.
Function GetNodesList(ByVal Node, ByRef NodesList)
    Dim i
    'Run on all children nodes
    For i = 1 To Node.Count
        Dim NewUpper
        'Add more space to dynamic array
        NewUpper = UBound(NodesList) + 1
        ReDim Preserve NodesList(NewUpper)
        
        'Add node path to array
        NodesList(NewUpper) = Node.Child(i).Path
        
        'If current node has a child then get path on child nodes too.
        If Node.Child(i).Count >= 1 Then
            Call GetNodesList(Node.Child(i), NodesList)
        End If
    Next
End Function



''
'Strips all the HTML tags from a string.
'
'@param:    strHTML A string with HTML tagges embedded.
'
'@return:               A string with all HTML tags stripped.
Function stripHTML(strHTML)
    'Strips the HTML tags from strHTML
    Dim objRegExp, strOutput
    Set objRegExp = New Regexp
    
    objRegExp.IgnoreCase = True
    objRegExp.Global = True
    objRegExp.Pattern = "<(.|\n)+?>"
    
    'Replace all line breaks with VB line breaks
    strOutput = Replace(strHTML, "<br>", vbLf)
    
    'Replace all HTML tag matches with the empty string
    strOutput = objRegExp.Replace(strOutput, "")
    
    'Replace all &lt;, &gt;, and &quot; with <, >, and "
    strOutput = Replace(strOutput, "&lt;", "<")
    strOutput = Replace(strOutput, "&gt;", ">")
    strOutput = Replace(strOutput, "&quot;", Chr(34))
    
    Set objRegExp = Nothing
    
    stripHTML = strOutput    'Return the value of strOutput
End Function



''
'Truncates a string to 32,767 characters for excel.
'
'@param:    strText String to be truncated.
'
'@return:               Truncated string.
Function Truncate(strText)
    'Excel Max Cell Length = 32,767 
    Dim sNotice
    sNotice = vbLf & "Contents Truncated..."
    
    If Len(strText) > 32767 Then
        strText = Left(strText, 32767 - Len(sNotice))
        strText = strText & sNotice
    End If
    
    Truncate = strText
End Function
Public Sub KillExcel ()
'Option explicit
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

    Set colProcesses = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'Excel.exe'")
    For Each objProcess in colProcesses
        objProcess.Terminate()
    Next
End Sub
Edited by joeloyzaga

Share this post


Link to post
Share on other sites

So how would I run a vbs program with the username and password I have just received then - lets use this function in vbs -which outputs to the screen

function displaythis(uname,pword)

msgbox("username: " & uname & "password: " & pword)

End Function

Like this:
#include <GuiConstantsEx.au3>

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

Global $Input_Password = "ThePassword"
Global $Input_Username = "TheUserName"

_Login()

Func _Login()
        $sCode = 'Function displaythis(uname,pword)' & _
                @LF & '  msgbox("username: " & uname & "  password: " & pword)' & _
                @LF & 'End Function' & @LF

        $Vbs = ObjCreate('ScriptControl')
        If @error Then
            MsgBox(16, 'Error', 'Error creating ScriptControl')
            Exit
        EndIf

        $Vbs.Language = 'VBScript'

        $Vbs.AddCode($sCode)

        $sRET = $Vbs.Run('displaythis', $Input_Username, $Input_Password)

        ConsoleWrite("$sRET = " & $sRET & @LF)
EndFunc   ;==>_Login

; Com Error Handler
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description, 3)
    ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)
    SetError(1); something to check for when this function returns
    Return
EndFunc   ;==>MyErrFunc

If the code is already in a VBScript file (YourScript.vbs), then you might just change _Login() this way:

Func _Login()
        Local $sCode = FileRead("C:\YourDir\YourScript.vbs")
        Local $Vbs = ObjCreate('ScriptControl')
        If @error Then
            MsgBox(16, 'Error', 'Error creating ScriptControl')
            Exit
        EndIf

        $Vbs.Language = 'VBScript'

        $Vbs.AddCode($sCode)

        $sRET = $Vbs.Run('displaythis', $Input_Username, $Input_Password)

        ConsoleWrite("$sRET = " & $sRET & @LF)
EndFunc   ;==>_Login

This can be limited though, because the ScriptControl environment has limitations that the full wscript (or cscript) environment does not, so maybe the script won't run this way. That takes us back to the original question: can't your AutoIt script just edit a copy of the .vbs file to set the variable's values as required for each run? Or mod the script with an input box as Juvigy said? How do you manually do it now?

>_<


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Embarassingly..... I had never thought of that.... and YES that would work magically

If I could run the login command "QCConnection.Login sUserName, sPassword" after running the aut login to get sUserName, sPassword

and then run this code to get the domain that the user is associated with (not allowing them to key it in anymore)

m_server.userName = sUserName

m_server.UserPassword = sPassword

' login to the project

m_server.LoginToProject

and receive the domain and project details

' retrieve all the domains projects from the TDServer

m_server.EnumDomains domainArray

If UBound(domainArray) <= 0 Then Exit Sub

For i = 1 To UBound(domainArray)

cbDomainList.AddItem domainArray(i)

If domainName = domainArray(i) Then

cbDomainList.value = domainName

End If

Next i

If cbDomainList.value = "" Then

cbDomainList.value = domainArray(1) ' default

End If

I could then edit the file to replace the domain details, prompt for report types and edit the file to enter these then run the file

Yes thats a plan - before I go this way - can I run this after receiving the login values?

"QCConnection.Login sUserName, sPassword" so I can get the domain values - then I'll try and get the domain values and prompt for report types - and then edit the file to run the report. Can you help me with that for a start?

Like this:

#include <GuiConstantsEx.au3>

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

Global $Input_Password = "ThePassword"
Global $Input_Username = "TheUserName"

_Login()

Func _Login()
        $sCode = 'Function displaythis(uname,pword)' & _
                @LF & '  msgbox("username: " & uname & "  password: " & pword)' & _
                @LF & 'End Function' & @LF

        $Vbs = ObjCreate('ScriptControl')
        If @error Then
            MsgBox(16, 'Error', 'Error creating ScriptControl')
            Exit
        EndIf

        $Vbs.Language = 'VBScript'

        $Vbs.AddCode($sCode)

        $sRET = $Vbs.Run('displaythis', $Input_Username, $Input_Password)

        ConsoleWrite("$sRET = " & $sRET & @LF)
EndFunc   ;==>_Login

; Com Error Handler
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description, 3)
    ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)
    SetError(1); something to check for when this function returns
    Return
EndFunc   ;==>MyErrFunc

If the code is already in a VBScript file (YourScript.vbs), then you might just change _Login() this way:

Func _Login()
        Local $sCode = FileRead("C:\YourDir\YourScript.vbs")
        Local $Vbs = ObjCreate('ScriptControl')
        If @error Then
            MsgBox(16, 'Error', 'Error creating ScriptControl')
            Exit
        EndIf

        $Vbs.Language = 'VBScript'

        $Vbs.AddCode($sCode)

        $sRET = $Vbs.Run('displaythis', $Input_Username, $Input_Password)

        ConsoleWrite("$sRET = " & $sRET & @LF)
EndFunc   ;==>_Login

This can be limited though, because the ScriptControl environment has limitations that the full wscript (or cscript) environment does not, so maybe the script won't run this way. That takes us back to the original question: can't your AutoIt script just edit a copy of the .vbs file to set the variable's values as required for each run? Or mod the script with an input box as Juvigy said? How do you manually do it now?

>_<

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