Skip to Content
avatar image
Former Member

VBScript conditional when trying to open a new SAP session?

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)
Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

0 Answers