Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Stefan-Schnell
Active Contributor
0 Kudos
4,727
Based on the discussion here I developed a function how to find the next logon screen of a given SID. The function delivers the connection number.
'-Begin--------------------------------------------------------------

'-Directives-------------------------------------------------------
Option Explicit

'-Function GetConnectionNo-----------------------------------------
'-
'- Function to get connection number of the given SID with
'- logon screen
'-
'------------------------------------------------------------------
Function GetConnectionNo(Application, SID)

'-Variables----------------------------------------------------
Dim i, Connection, SessionInfo, ConnectionNo

If Application.Children.Count > 0 Then
For i = 0 To Application.Children.Count - 1
Set Connection = Application.Children(CInt(i))
Set SessionInfo = Connection.Children(0).Info
If SessionInfo.SystemName = SID And _
SessionInfo.Program = "SAPMSYST" Then
ConnectionNo = Mid(Connection.Id, InStr(Connection.Id, "[") + 1)
ConnectionNo = Left(ConnectionNo, Len(ConnectionNo) - 1)
GetConnectionNo = CStr(ConnectionNo)
End If
Next
Else
GetConnectionNo = -1
End If

End Function

'-Sub Main---------------------------------------------------------
Sub Main()

'-Variables----------------------------------------------------
Dim SapGuiAuto, Application, ConnNo

If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set Application = SapGuiAuto.GetScriptingEngine
End If

ConnNo = GetConnectionNo(Application, "NSP")

MsgBox ConnNo

End Sub

'-Main-------------------------------------------------------------
Main

'-End----------------------------------------------------------------

 
12 Comments
Labels in this area