Quantcast
Channel: SCN : Blog List - All Communities
Viewing all articles
Browse latest Browse all 2548

How to Find the Next Logon Screen of a SID with SAP GUI Scripting

$
0
0

Hello community,

 

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----------------------------------------------------------------

 

Enjoy it.

 

Cheers

Stefan


Viewing all articles
Browse latest Browse all 2548

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>