7

My SAP-GUI has Scripting installed and Scripting is enabled.

Like in this screenshot:

sap-gui-config--scripting-enabled

In this Introduction to SAP GUI Scripting in "Step 2: Setup your SAP System" you need to call RZ11.

I don't have permissions to call RZ11.

Is there a way to detect this (sapgui/user_scripting on or off) via a script?

At the moment I use below code, but the list of connections is always empty:

import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
sapgui = win32com.client.GetObject("SAPGUI")
system = query.get('system')
client = query.get('mandant')
session = False
application = sapgui.GetScriptingEngine
seen = []
for i_conn in range(0, application.Connections.Count):
    seen.append('i_conn=%s session_count=%s' % (i_conn, application.Connections.Item(i_conn).Sessions.Count))
    for i_sess in range(0, application.Connections.Item(i_conn).Sessions.Count):
        session_info = application.Connections.Item(i_conn).Sessions.Item(i_sess).Info
        system_of_session = session_info.SystemName
        client_of_session = session_info.Client
        if system_of_session == system and client_of_session == client:
            connection = application.Connections.Item(i_conn).Children(i_sess)
            session = connection.Children(i_sess)
            break
        seen.append('system=%s client=%s' % (system_of_session, client_of_session))
    if session:
        break

else:
    info_popup('You are not logged into system %s in Client %s! Seen:\n%s' % (
        system, client, '\n'.join(seen)))
    return
Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
guettli
  • 25,042
  • 81
  • 346
  • 663

3 Answers3

1

When you don't have sufficient priviledges in sap, the fact that you can't connect is a pretty good indication that the user does not have scripting enable (assuming the user has a active sap session running), other wise you could just test with 'session.findById("wnd[0]/usr/tblSAPLCMDITCTRL_3500").getAbsoluteRow(3).selected = true' and check for errors. Also, I suggest you factor in "SAPGUISERVER' in your sapgui = win32com.client.GetObject("SAPGUI") connection if "SAPGUI" fails.

OzzyMiner
  • 41
  • 3
0

As I know sapgui/user_scripting is a system-level = application level setting but not a user-level. So, if you have no permissions to run RZ11 tcode then you have no opportunity or permissions to read applicaton server settings and, of course, no permissions to change it. You have to contact your basis administrator to verify this application settings with him. You see, SAP limited scripting abilities due to possible vulnerability, that's why scripting support should be turned on both on client side and on application server side.

Sergey M
  • 169
  • 5
0

If you have access to interrogate the registery you could write a cutom function to check SAPGUI is installed and flagged e.g:

Public Sub CheckKey()

    Const cRegKey As String = "HKEY_CURRENT_USER\Software\SAP\SAPGUI Front\SAP Frontend Server\Security\UserScripting"
    If CheckSAPGUI(cRegKey) Then
        MsgBox "User has SAPGUI installed and initialized", vbOKOnly Or vbInformation, Application.Name
    Else
        MsgBox "User does not have SAPGUI installed", vbOKOnly Or vbCritical, Application.Name
    End If

End Sub


Public Function CheckSAPGUI(RegKey As String) As Boolean

    Dim rtn As Variant

    On Error Resume Next
    rtn = vbNullString

    With CreateObject("wscript.shell")
        rtn = .RegRead(RegKey)
    End With

    If Len(rtn) = 0 Then
        CheckSAPGUI = False
    ElseIf Val(rtn) <> 1 Then
        CheckSAPGUI = False
    Else
        CheckSAPGUI = True
    End If

    On Error GoTo 0
End Function

You should be able to modify the MsgBox comments to better suit how you want to interact with your end user

OzzyMiner
  • 41
  • 3