代码之家  ›  专栏  ›  技术社区  ›  Piotr Wojsa

使用SNC/SSO编写SAP GUI脚本

  •  0
  • Piotr Wojsa  · 技术社区  · 6 年前

    我正在尝试使用SNC连接和用户名和密码(不是自动)使用sapgui脚本登录SAP。 在我的连接列表中,有一个目标服务器的自动登录设置为true。 我知道可以再次添加同一个服务器,并将auto logon设置为false并选择它,但是客户端不想在列表中添加其他位置。 通常(没有SNC)我只使用

    CSapROTWrapper sapROTWrapper = new CSapROTWrapper();
    var SapGuilRot = sapROTWrapper.GetROTEntry("SAPGUI");
    var engine = SapGuilRot.GetType().InvokeMember("GetScriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, SapGuilRot, null);
    var GuiApp = (GuiApplication)engine;
    var connection = GuiApp.OpenConnection("My server name", true, true);
    

    然后我可以输入用户名和密码。 但是,使用SNC和autologon,我已经使用SNC中的凭据登录(我想使用不同的凭据,而不使用SNC做任何事情)。

    var connection = GuiApp.OpenConnectionByConnectionString("my.server.address", true, true);
    

    /H/ip.add.res.s/S/3200&sncon=true&sncname=properName&sncqop=4
    

    但每次连接都没有建立信息:

    无法实例化“Sapgui组件”

    0 回复  |  直到 6 年前
        1
  •  2
  •   Piotr Wojsa    5 年前

    这个问题比我预料的要容易解决。我想我花了太多的时间,我没有检查最简单的选择。 使用连接字符串是正确的,但我找不到我的连接字符串。

    var sapROTWrapper = new CSapROTWrapper();
    var sapGuilRot = sapROTWrapper.GetROTEntry("SAPGUI");
    var engine = sapGuilRot.GetType().InvokeMember("GetScriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, sapGuilRot, null);
    var guiApp = (GuiApplication)engine;
    var existingConnection = (GuiConnection)guiApp.Connections.ElementAt(0);
    var properConnectionString = existingConnection.ConnectionString;
    

    然后我所需要做的就是保存这个连接字符串并重新登录以使用它。

    var sapROTWrapper = new CSapROTWrapper();
    var sapGuilRot = sapROTWrapper.GetROTEntry("SAPGUI");
    var engine = sapGuilRot.GetType().InvokeMember("GetScriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, sapGuilRot, null);
    var guiApp = (GuiApplication)engine;
    var connectionString = "connection string read from previous run";
    var connection = guiApp.OpenConnectionByConnectionString(connectionString, true, true);