Untitled
unknown
plain_text
9 months ago
1.5 kB
3
Indexable
using System;
using System.Runtime.InteropServices;
using SAPFEWSELib; // Import SAP GUI Scripting API
namespace SAPAutomation
{
class Program
{
static void Main(string[] args)
{
try
{
// Attach to SAP GUI
GuiApplication sapGuiApp = (GuiApplication)Marshal.GetActiveObject("SapGui.ScriptingCtrl.1");
GuiConnection sapConnection = (GuiConnection)sapGuiApp.Children.ElementAt(0);
GuiSession sapSession = (GuiSession)sapConnection.Children.ElementAt(0);
// Display the available SAP sessions
Console.WriteLine("Connected to SAP System: " + sapConnection.Name);
// Find username/password fields & login button (You need to find correct IDs from SAP)
GuiTextField userField = (GuiTextField)sapSession.FindById("wnd[0]/usr/txtRSYST-BNAME");
GuiTextField passwordField = (GuiTextField)sapSession.FindById("wnd[0]/usr/pwdRSYST-BCODE");
GuiButton loginButton = (GuiButton)sapSession.FindById("wnd[0]/tbar[1]/btn[0]");
// Perform login
userField.Text = "your_username";
passwordField.Text = "your_password";
loginButton.Press();
Console.WriteLine("Login Successful!");
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
}
}
Editor is loading...
Leave a Comment