public static GuiConnection CreateConnection(string description, string user, string password, string language) { CSapROTWrapper sapROTWrapper = new CSapROTWrapper(); object SapGuilRot = sapROTWrapper.GetROTEntry("SAPGUI"); object engine = SapGuilRot.GetType().InvokeMember("GetSCriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, SapGuilRot, null); GuiApplication app = (GuiApplication)engine; GuiConnection conn; if (app.Connections.Count == 0) { conn = app.OpenConnection(description); GuiSession session = conn.Children.ElementAt(0) as GuiSession; GuiTextField name = (GuiTextField)session.FindById("wnd[0]/usr/txtRSYST-BNAME"); GuiPasswordField pass = (GuiPasswordField)session.FindById("wnd[0]/usr/pwdRSYST-BCODE"); GuiTextField lang = (GuiTextField)session.FindById("wnd[0]/usr/txtRSYST-LANGU"); GuiMainWindow mainWindows = (GuiMainWindow)session.FindById("wnd[0]"); name.Text = user; pass.Text = password; lang.Text = language; mainWindows.SendVKey(0); } else { conn = (GuiConnection)app.Connections.ElementAt(0); } return(conn); }
public static void SendKey(this GuiMainWindow Window, SAPKeys key) { Window.SendVKey((int)key); }