获取运行Sap登录vb6的GuiApplication到c#

前端之家收集整理的这篇文章主要介绍了获取运行Sap登录vb6的GuiApplication到c#前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我必须将vb6程序迁移到C#.net 3.5
用户启动SAP登录并进行身份验证,
然后他可以使用该工具使用该工具获取和插入数据
问题:
我可以使用反射创建一个新的GuiApplication,但我无法用它来获取当前打开的GuiSessions:/
这是当前打开GuiApplication所有打开的GuiSessions的代码的vb6部分
Dim obj As Object
    Set obj = CreateObject("SAPGUI")
    Set obj = obj.GetScriptingEngine

    If TypeName(obj) = "GuiApplication" Then
        Set SapAutomationObject = obj
        SapAutomationObject.AllowSystemMessages = False

        Debug.Print "SAP Automation OK"
    End If

我试着反思:

GuiApplication Application = (GuiApplication)System.Activator.CreateInstance(Type.GetTypeFromProgID("SapGui.S‌​criptingCtrl.1"));

我有一个实例,但没有现有的会话

public static void testConnection()
        {
            SapROTWr.CSapROTWrapper sapROTWrapper = new SapROTWr.CSapROTWrapper();
            object SapGuilRot = sapROTWrapper.GetROTEntry("SAPGUI");
            object engine = SapGuilRot.GetType().InvokeMember("GetSCriptingEngine",System.Reflection.BindingFlags.InvokeMethod,null,SapGuilRot,null);
            SAPconnection.sapGuiApp = engine as GuiApplication;
            GuiConnection connection = sapGuiApp.Connections.ElementAt(0) as GuiConnection;
            GuiSession session = connection.Children.ElementAt(0) as GuiSession;
            MessageBox.Show(session.Info.User + " !!||!! " + session.Info.Transaction);


        }

使用此方法,您必须引用SAP安装的sapgui文件夹中的SapROTWr.DLL.

原文链接:https://www.f2er.com/vb/255293.html

猜你在找的VB相关文章