on 12-22-2022 9:14 AM
<code>Option Explicit
Dim WSHShell, SAPGUIPath, SID, InstanceNo, WinTitle, Name
Set WSHShell = WScript.CreateObject("WScript.Shell")
If IsObject(WSHShell) Then
SAPGUIPath = "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\"
SID = "RA4"
InstanceNo = "00"
WSHShell.Exec SAPGUIPath & "sapgui.exe " & SID & " " & _
InstanceNo
WinTitle = "SAP"
While Not WSHShell.AppActivate(WinTitle)
WScript.Sleep 250
Wend
Set WSHShell = Nothing
End If
'Delay for the log in window to be visible
WScript.Sleep 5000
Dim SAPGUI, proc, Appl, application, SapGuiAuto, connection, session,
Set session = StablishSession() 'Set up session with SAP
If not session is Nothing then 'If connection was stablished to SAP
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/txtRSYST-BNAME").text = username
session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = password
session.findById("wnd[0]/usr/pwdRSYST-BCODE").setFocus
session.findById("wnd[0]/usr/pwdRSYST-BCODE").caretPosition = 12
session.findById("wnd[0]").sendVKey 0
End if
'create session in SAP
Function StablishSession
On Error Resume Next
If Not IsObject(Application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set Application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = Application.Children(0)
End If
If Err.Number <> 0 Then
Msgbox "SAP Session must be open first"
Set StablishSession = Nothing
On Error Goto 0
Else
If Not IsObject(session) Then
Set session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject Application, "on"
End If
Set StablishSession = session
end if
End Function
I'm trying to log in to multiple SID (Sample: RA4,ZZZ,YYY). Let's say I will log in to RA4 and I run the vbscript, it will work perfectly(able to log in username and password). Then I want to log in to ZZZ without logging out to RA4, this vbscript failed from line "session.findById("wnd[0]/usr/txtRSYST-BNAME").text = username". Also it maximizes the first session window which is RA4 and not the second window which is ZZZ. The script stop showing the log in window without text on username and password field then maximizing the first session window (RA4).
User | Count |
---|---|
76 | |
9 | |
8 | |
6 | |
6 | |
5 | |
5 | |
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.