on 10-17-2012 8:34 PM
Hello,
I am developing a console app in VB.net which will run automatically using windows task schedule service. The program will extract information from SAP GUI around 10 times at day, so I am trying to find a way to close the SAP Windows once the program is terminated otherwise I will have hundred of SAP windows opened because there will not be a user in the computer where the program will run.
My connection script is as follows:
Dim SapGuiAuto = GetObject("SAPGUI")
Dim application = SapGuiAuto.GetScriptingEngine
Dim connection = application.OpenConnection("system", True, False)
Dim MySession = connection.Children.Item(0)
MySession.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "user"
MySession.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "password"
MySession.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "E"
MySession.findById("wnd[0]").sendVKey(0)
MySession.findById("wnd[0]/tbar[0]/okcd").Text = "/nzdown1"
MySession.findById("wnd[0]").sendVKey(0)
MySession.findById("wnd[0]/usr/btn%_SMATNR_%_APP_%-VALU_PUSH").press()
MySession.findById("wnd[1]/tbar[0]/btn[24]").press()
MySession.findById("wnd[1]").sendVKey(8)
MySession.findById("wnd[0]/usr/chkP_LOC1").Selected = False
MySession.findById("wnd[0]/usr/chkP_LOC2").Selected = False
MySession.findById("wnd[0]/usr/chkP_LOC3").Selected = False
MySession.findById("wnd[0]/usr/chkP_LOC3").SetFocus()
MySession.findById("wnd[0]").sendVKey(8)
MySession.findById("wnd[1]/usr/ctxtRLGRAP-FILENAME").Text = "c:\class.txt"
MySession.findById("wnd[1]/usr/ctxtRLGRAP-FILENAME").caretPosition = 12
MySession.findById("wnd[1]").sendVKey(0)
' HERE IS WHERE I WANT TO CLOSE THE SAP WINDOWS
MySession = Nothing
connection = Nothing
application = Nothing
SapGuiAuto = Nothing
End Sub
Hi Magda,
welcome to the forum. You can try the following:
. . .
while connection.children.count > 0
Set MySession = connection.Children(0)
MySession.findbyid("wnd[0]").close
on error resume next
MySession.findById("wnd[1]/usr/btnSPOP-OPTION1").press
on error goto 0
wend
This variant of VBS-Code terminates all open SAP sessions.
Regards,
ScriptMan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just an FYI to shorten it further without error handling manipulation.
Instead of:
on error resume next
MySession.findById("wnd[1]/usr/btnSPOP-OPTION1").press
on error goto 0
Use:
if not MySession.findById("wnd[1]/usr/btnSPOP-OPTION1", false) is nothing then MySession.findById("wnd[1]/usr/btnSPOP-OPTION1").press
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.