Hello community,
via e-mail I received a question how to get the next input-ready session of a SID in AutoIt scripting language. Here a solution.
It should now not be difficult to combine this approach with this approach to find a special session, e.g. the logon screen. It is only necessary to add the SessionInfo.Program attribute.
;-Begin-----------------------------------------------------------------
;-Directives----------------------------------------------------------
AutoItSetOption("MustDeclareVars", 1)
;-Function GetSessionOfSID--------------------------------------------
;-
;- Delivers the first non busy session of a SID
;-
;---------------------------------------------------------------------
Func GetSessionOfSID($Application, $SID)
;-Local Variables-------------------------------------------------
Local $i, $Connection, $j, $Session, $SessionInfo
If $Application.Children.Count > 0 Then
For $i = 0 To $Application.Children.Count - 1
$Connection = $Application.Children($i)
For $j = 0 To $Connection.Children.Count - 1
If $Connection.Children($j).Busy = False Then
$Session = $Connection.Children($j)
$SessionInfo = $Session.Info
If $SessionInfo.SystemName = $SID Then
Return $Session
EndIf
EndIf
Next
Next
EndIf
EndFunc
;-Sub Main------------------------------------------------------------
Func Main()
;-Local Variables-------------------------------------------------
Local $SAPROT, $SapGuiAuto, $Application, $Session
$SAPROT = ObjCreate("SapROTWr.SAPROTWrapper")
If Not IsObj($SAPROT) Then
Return
EndIf
$SapGuiAuto = $SAPROT.GetROTEntry("SAPGUI")
If Not IsObj($SapGuiAuto) Then
Return
EndIf
$Application = $SapGuiAuto.GetScriptingEngine()
If Not IsObj($Application) Then
Return
EndIf
$Session = GetSessionOfSID($Application, "NSP")
If IsObj($Session) Then
;Your script code here
MsgBox(0, "", $Session.Id)
EndIf
$Application = 0
$SapGuiAuto = 0
$SAPROT = 0
EndFunc
;-Main----------------------------------------------------------------
Main()
;-End-------------------------------------------------------------------
Enjoy it.
Cheers
Stefan