davidm / luacom

Microsoft Component Object Model (COM) binding for Lua
http://lua-users.org/wiki/LuaCom
Other
116 stars 51 forks source link

SAP connection #11

Open trax100 opened 10 years ago

trax100 commented 10 years ago

Hi, does anybody tryied connect to SAP Gui and its ScriptingEngine??? In VBScript you have to run this code

    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
    If IsObject(WScript) Then
       WScript.ConnectObject session,     "on"
       WScript.ConnectObject application, "on"
    End If

    session.findById("wnd[0]").maximize

But in LuaCOM it failed at connection = application:Children(0) see the Lua code

function help(t)
    for k,v in pairs(t) do print(k,v) end
end

require("luacom")

-- luacom.config.abort_on_API_error = true
-- luacom.config.abort_on_error = false

print("SapGuiAuto")
-- local Wrp = luacom.CreateObject ("SapROTWr.SapROTWrapper")
-- local SapGuiAuto = Wrp:GetROTEntry ("SAPGUI")
local SapGuiAuto  = luacom.GetObject("SAPGUI")
if not SapGuiAuto then error("SapGuiAuto missing") else help(SapGuiAuto) end
print()

print("application")
local application = SapGuiAuto:GetScriptingEngine()
if not application then error("application failed") else help(application) end
print()

print("connection")
local connection = application:Children(0)
if not connection then error("connection failed") else help(connection) end
print()

print("session")
local session = connection:Children(0)
if not session then error("session failed") else help(session)end
print()

   -- WScript.ConnectObject session,     "on"
   -- WScript.ConnectObject application, "on"

-- session.findById("wnd[0]").maximize

print("working") 

Program output:


c:\l>bin\lua.exe SAPconnect.lua SapGuiAuto _USERDATAREF userdata: 0071A000

application _USERDATAREF userdata: 01E52AC0

connection

c:\l>