I have got Python and Visual Basic working. I am struggling to find a working solution for C# although I understand that it should be available and relatively similar to Visual Basic, right? I don't have SAP GUI DLL's on my development machine, so I can't just add reference to it.
So in Python this is working fine:
#-Begin-----------------------------------------------------------------
#-Includes--------------------------------------------------------------
import sys, win32com.client
#-Sub Main--------------------------------------------------------------
def Main():
SapGuiAuto = win32com.client.GetObject("SAPGUI")
if not type(SapGuiAuto) == win32com.client.CDispatch:
return
application = SapGuiAuto.GetScriptingEngine
if not type(application) == win32com.client.CDispatch:
SapGuiAuto = None
return
connection = application.Children(0)
if not type(connection) == win32com.client.CDispatch:
application = None
SapGuiAuto = None
return
session = connection.Children(1)
if not type(session) == win32com.client.CDispatch:
connection = None
application = None
SapGuiAuto = None
return
#session.findById("wnd[0]").resizeWorkingPane 173, 36, 0
session.findById("wnd[0]").resizeWorkingPane(173, 36, 0)
In Visual Basic similar would be:
Sub Main
Set SapGuiAuto = GetObject("SAPGUI")
Set Application = SapGuiAuto.GetScriptingEngine
Set Connection = Application.openConnection("EQ2")
Set Session = Connection.Children(0)
Session.ActiveWindow.Iconify()
Session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "410"
Session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "XYZ"
Session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "Pwd1"
Session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"
Session.findById("wnd[0]").SendVKey 0
End Sub
Or this:
Sub SAP_OpenSessionFromLogon()
Dim SapGui
Dim Applic
Dim connection
Dim session
Shell ("C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapfewcp.exe")
Set SapGui = GetObject("SAPGUI")
Set Applic = SapGui.GetScriptingEngine
Set connection = Applic.OpenConnection("QLA - ECC Project One Quality System", True) '<=== here you need to fillin your connection description
End Sub
How to do the same in C# without adding reference to SAP GUI COM DLL or is it even possible without it? I mean just to open some exe on computer, bring windows foreground and send automate GUI?