cancel
Showing results for 
Search instead for 
Did you mean: 

VB Script to Close All Active Sessions of SAP and Exit SAP

Former Member
0 Kudos

Hi,

I'm wondering if anyone can share vb script to close all active SAP if any. And then another one that will close the SAP app if it is running.

Thanks.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

thanks!

script_man
Active Contributor
0 Kudos

Hi Brit,

this question would be better placed in Scripting Languages. But I did read it anyway.

You could try the following:

for example:

PATH = "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe"

on error resume next

Set SapGuiAuto  = GetObject("SAPGUI")

if err.number <> 0 then

msgbox " 'SAP Logon' is not active.", vbInformation, "Information"

else

on error goto 0

Set application = SapGuiAuto.GetScriptingEngine

on error resume next

Set connection = application.Children(0)

if err.number <> 0 then

    msgbox " No SAP - Session is active.", vbInformation, "Information"

else

    on error goto 0

    while connection.children.count > 0

      Set session    = connection.Children(0)

      session.findbyid("wnd[0]").close

      on error resume next

      session.findById("wnd[1]/usr/btnSPOP-OPTION1").press

      on error goto 0

    wend

end if

set wshell = createObject("Wscript.Shell")

wshell.run chr(34) & PATH & chr(34)

wscript.Sleep 500

bWindowFound = Wshell.AppActivate("SAP Logon")

if bWindowFound then

    Wshell.appActivate "SAP Logon"

    WScript.Sleep 200

    Wshell.sendkeys "%{F4}"

    WScript.Sleep 200

end if

end if

Of course there are many other solutions that are much more elegant.

Regards,

ScriptMan