Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8623

Re: VB Script: check for existing open session

$
0
0
Sub Get_all_SAP_Sessions()    Dim SapGuiAuto As Object    Dim i%    Dim iSession%    Dim sapapplication    Dim Connection As SAPFEWSELib.GuiConnection    Dim Session As SAPFEWSELib.GuiSession    Dim strSessions$    i = 1    iSession = 0    ' There may be bad entries in the ROT from previous crashes    While i < 10 And SapGuiAuto Is Nothing       i = i + 1       On Error Resume Next       Set SapGuiAuto = GetObject("SAPGUI")       On Error GoTo 0    Wend    If SapGuiAuto Is Nothing Then        MsgBox "Could not connect to SAPlogon process. Did you start it?"        Exit Sub    End If        On Error Resume Next    Set sapapplication = SapGuiAuto.GetScriptingEngine    Set SapGuiAuto = Nothing    On Error GoTo 0    If sapapplication Is Nothing Then        MsgBox "Could not access GuiApplication. Maybe Scripting is disabled?"        Exit Sub    End If    Set SapGuiAuto = Nothing        For Each Connection In sapapplication.Children        If Not Connection.DisabledByServer Then            For Each Session In Connection.Children                If Session.Busy = False Then                    iSession = iSession + 1                    strSessions = strSessions & iSession & " => " & (Session.Info.SystemName & _                    " (" & CStr(Session.Info.SessionNumber) & _                    ") (" & Session.Info.Client & ") | User: " & _                    Session.Info.User & " | Transaction: " & _                    Session.Info.Transaction) & vbCrLf & iSession & " => System-ID: " & Session.ID & vbCrLf                End If            Next        End If    Next    MsgBox strSessions
End Sub

 

Above an example how I achieve to get all available SAP Sessions. Additional I implement an check if a Session is busy. In this case it will skip to get session info as this will block the check macro.

 

Holger


Viewing all articles
Browse latest Browse all 8623

Trending Articles



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