Skip to Content
author's profile photo Former Member
Former Member

SAPGUI Script in C# not working

Hey guys,

I'm coding C# to automate some SAPGUI scripting, and I have this wired problem...

Below is the code piece

GuiApplication guiApp = (GuiApplication)System.Activator.CreateInstance(Type.GetTypeFromProgID("SapGui.ScriptingCtrl.1"));

GuiConnection guiConn = guiApp.OpenConnection("MYSYSTEM", true, true);

GuiSession guiSession = (GuiSession)guiConn.Sessions.Item(0);

GuiFrameWindow guiWindow = guiSession.ActiveWindow;

GuiTextField client = (GuiTextField)guiWindow.FindByName("RSYST-MANDT", "GuiTextField");

GuiTextField login = (GuiTextField)guiWindow.FindByName("RSYST-BNAME", "GuiTextField");

GuiTextField pass = (GuiTextField)guiWindow.FindByName("RSYST-BCODE", "GuiPasswordField");

GuiTextField language = (GuiTextField)guiWindow.FindByName("RSYST-LANGU", "GuiTextField");

client.SetFocus();

client.Text = "XXX";

login.SetFocus();

login.Text = "XXXXXXX";

pass.SetFocus();

pass.Text = "XXXXXXX";

language.SetFocus();

language.Text = "XX";

This code piece worked 100% fine a week ago, but it's not working now... The problem now is that guiConn.Session contains no items after OpenConnection. I'm coding in Visual Studio 2008, I don't think I did any change to my VS project.

I tried guiConn.Children, it contains no items either.

Please help!!!

Thanks,

Shu

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on May 10, 2013 at 12:46 PM

    Check your references,

    If SAPFEWSELIB is not referenced this will not work, I just compiled this and it works (VS.Net 2012 Express)

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

    using SAPFEWSELib;

    namespace ConsoleApplication1

    {

    class Program

    {

    static void Main(string[] args)

    {

    GuiApplication guiApp = (GuiApplication)System.Activator.CreateInstance(Type.GetTypeFromProgID("SapGui.ScriptingCtrl.1"));

    GuiConnection guiConn = guiApp.OpenConnection("mysystem", true, true);

    GuiSession guiSession = (GuiSession)guiConn.Sessions.Item(0);

    GuiFrameWindow guiWindow = guiSession.ActiveWindow;

    ((GuiTextField)guiWindow.FindByName("RSYST-MANDT", "GuiTextField")).Text = "000";

    ((GuiTextField)guiWindow.FindByName("RSYST-BNAME", "GuiTextField")).Text="lesteban";

    ((GuiTextField)guiWindow.FindByName("RSYST-BCODE", "GuiPasswordField")).Text="mypassword";

    ((GuiTextField)guiWindow.FindByName("RSYST-LANGU", "GuiTextField")).Text="en";

    guiWindow.SendVKey(0);

    Console.ReadLine();

    }

    }

    }

    regards

    Luis

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.