How to use Windows PowerShell to interface with InfoConnect Desktop via .NET API

  • 7025237
  • 06-Aug-2021
  • 16-Sep-2021

Environment

InfoConnect Desktop (including Pro, Unisys, and Airlines) 16.0 or higher

Situation

This technical article describes how to use Windows PowerShell to interface with InfoConnect Desktop via the Reflection .NET API and includes some sample code.

Resolution

The following Windows PowerShell script uses embedded C# code and the Reflection/InfoConnect Desktop .NET API to connect to a UTS session.  The sample code builds a UTS connection to a mainframe system and displays the Host screen then exits. This code was written and tested with InfoConnect Desktop 17.0 with the “Application Programmer Interface” installed in the InfoConnect Desktop Feature Tree.  (this feature is not installed by default).  This sample code will display a few status messages and the UTS session screen in the PowerShell Window as it executes.

Paste the following in the Windows PowerShell window and press the ENTER key:

$Assem = (
    "C:\Program Files (x86)\Micro Focus\InfoConnect\Programmer Interfaces\Attachmate.Reflection.dll",
    "C:\Program Files (x86)\Micro Focus\InfoConnect\Programmer Interfaces\Attachmate.Reflection.Framework.dll",
    "C:\Program Files (x86)\Micro Focus\InfoConnect\Programmer Interfaces\Attachmate.Reflection.Emulation.UTS.dll"
)
 
$Source = @'
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using Attachmate.Reflection.Framework;
using Attachmate.Reflection.UserInterface;
using Attachmate.Reflection.Emulation.UTS;
 
public class InfoConnectProgram
{
    public static object ConnectSession()
    {
        Console.WriteLine(" ");
        Console.WriteLine("Main - Start");
 
        // Create an application object
        Attachmate.Reflection.Framework.Application app = MyReflection.CreateApplication("myWorkspace", true);
 
        // Create a terminal by opening the session file
        string sessionFileUTS = Environment.GetEnvironmentVariable("USERPROFILE") + @"\Documents\Micro Focus\InfoConnect\UTSSession.iuts";
        IUtsTerminal terminalUTS = (IUtsTerminal)app.CreateControl(sessionFileUTS);

        // Make the session visible                 
        IFrame frame = (IFrame)app.GetObject("Frame");
        IView sessionViewUTS = frame.CreateView(terminalUTS);
        IUtsScreen screen = terminalUTS.Screen;

        Console.WriteLine("Completed:   Connecting...");
         
        string UTSScreenData;
        UTSScreenData = screen.GetText(1, 1, 1920);
        Console.WriteLine (UTSScreenData);

        Console.WriteLine("Main - End");
        Console.WriteLine(" ");
        Console.WriteLine("Test Program complete - Exiting...");
        return screen;
    }
}
'@
Add-Type -ReferencedAssemblies $Assem -TypeDefinition $Source -language CSharp
[InfoConnectProgram]::ConnectSession()

Additional Information