Skip to Content

VBScript conditional when trying to open a new SAP session?

May 03 at 04:36 PM


avatar image
Former Member

I have the following vbs code, that opens a new SAP session.

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\"
    Name = """1. SAP ECC Production (PRD)"""
    SID = "PRD"
    InstanceNo = "00"
    WSHShell.Exec SAPGUIPath & "sapgui.exe " & Name & " " & _
    WinTitle = "SAP"
    While Not WSHShell.AppActivate(WinTitle)
      WScript.Sleep 250
    Set WSHShell = Nothing
End If

There are two scenarios when executing it:

  1. First, there's no other SAP session running, so works well, no issue here.
  2. Second, there´s another SAP session already running, so the following windows is popped up.

What I want is to add a conditional to the code, that if the first case happens, does nothing, and if the second case occurs, selects the marked option,

Can anybody help me out please?

untitled.png (24.6 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers