Skip to Content
Technical Articles
Author's profile photo Stefan Schnell

How an SAP GUI Script is Executed

There are several ways to execute an SAP GUI script:

  1. Via SAP GUI recorder, press Alt+F12, now choose the menu item Script Recording and Playback, load the script file and press Playback button.
  2. Via Drag’n’Drop with the script file to the session where the script should be executed.
  3. Via double click on the script file in the Windows Explorer.
  4. Via the command line in a console window with the command wscript.exe or cscript.exe and the name of the script file.

This are four ways but technically this are only two ways. One and two works technically equal, also as three and four.

One and two executes the script via MSScriptControl. This means that the SAP GUI for Windows instanciate the class MSScriptControl.ScriptControl from the msscript.ocx library and executes the SAP GUI Script as statement – I think.

To check it out I create the following test script:


  If Not IsObject(application) Then
    Set SapGuiAuto  = GetObject("SAPGUI")
    Set application = SapGuiAuto.GetScriptingEngine
  End If

  If Not IsObject(connection) Then
    Set connection = application.Children(0)
  End If

  If Not IsObject(session) Then
    Set session    = connection.Children(0)
  End If

  session.findById("wnd[0]/tbar[0]/okcd").text = "/nSE16"

  WScript.Sleep 500
  WScript.Echo "Test"



The reaction with one and two are


To see reaction in a simulated context of SAP GUI for Windows I create the following test script:


    Option Explicit

    Dim ScrCtrl, Cmd

    Set ScrCtrl = CreateObject("MSScriptControl.ScriptControl")
    If IsObject(ScrCtrl) Then

      ScrCtrl.AllowUI = vbTrue
      ScrCtrl.Language = "VBScript"

      Cmd = "WScript.Echo ""Hello World"""
      ScrCtrl.ExecuteStatement Cmd

    End If



The reaction is the same as one and two



This knowledge gives us now a good base to understand the behaviour of the different executions forms better. On the one hand via MSScriptControl, on the other hand via WScript.

Hint: If you work with WScript you must define the connection (application.Children(x)) and session (connection.Children(y)) with correct values – here x and y as example. The standard defines always 0 – which means connection 0 and session 0, the first connection and session in the pool of all open connections and sessions.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.