3422 Old Capitol Trail – Suite 1125, Wilmington – DE 19808, United States

How to programmatically register Thinfinity® VirtualUI™ applications

thinfinitycodegears

Thinfinity VirtualUI comes with a configuration library that allows for an automatic and transparent programmatic registration of an application on your Thinfinity VirtualUI Server. This way, you can avoid leaving this registration and configuration process in the hands of the end user.

Thinfinity VirtualUI’s configuration library allows you to:

  • Activate/deactivate licenses.
  • Manage Remote Desktop accounts (RDS accounts).
  • Configure general server settings.
  • Manage certificates.
  • Create and/or modify profiles, as we do from the manager.
  • Hide or display manager options.

The following examples, written in Delphi and C#, explain how to create and/or modify (if it already exists) the registration (profile) of an application.

Delphi Version:

procedure TFormMain.createProfileButtonClick(Sender: TObject);
var
  profiles: IProfiles;
  profile: IProfile;
  icon: TPngImage;
  virtualPath: string;
  p: integer;
begin
  virtualPath := 'demoapp';
  profile := nil;
  profiles := Server.Profiles;

  // Check if the profile to create already exists.
  // In this case, we've been using the VirtualPath which,
  //   if defined, must be unique.
  // We could check by a different field.
  // For example, by the executable path and name.
  p := 0;
  while ((p < profiles.Count) and not Assigned(profile)) do
  begin
     if (profiles.Item[p].VirtualPath = virtualPath) then
         profile := profiles.Item[p]
     else
         Inc(p);
  end;
  if (not Assigned(profile)) then
  begin
     // Adds a new empty profile to the Server:
     profile := Server.Profiles.Add;
     // Set the VirtualPath property (this value must be unique).
     profile.VirtualPath   := 'demoapp';
  end;

  // Set basic profile properties:
  // - UserName and Password must be a valid Windows Account
  //   in the VirtualUI server machine:
  profile.Name          := 'Demo Application';
  profile.FileName      := 'C:\path_to_app\demo.exe';
  profile.UserName      := 'windows_user';
  profile.Password      := 'user_password';
  profile.ProfileKind   := PROFILE_App;
  // If needed, you can set other properties
  // like Arguments, StartDir, etc.

  // Set profile icon, in this case from external file
  // (you can also extract the application icon,
  // convert to PNG, and pass to IconToBase64):
  icon := TPngImage.Create;
  icon.LoadFromFile('demo_icon.png');
  profile.IconData := IconToBase64(icon);
  icon.Free;

  // Save changes:
  Server.Save;
end;

.Net (C#) Version:

using Cybele.Thinfinity.Settings.VirtualUI;
…

private Server m_VirtualUIConfig = new Server();
…

private void createProfileButton_Click(object sender, EventArgs e)
{
    string virtualPath = "demoapp";
    IProfile profile = null;
    IProfiles profiles = m_VirtualUIConfig.Profiles;

    // Check if the profile to create already exists.
    // In this case, we've been using the VirtualPath which,
    // if defined, must be unique.
    // We could check by a different field. for example,
    // by the executable path and name.

    int p = 0;
    while (p < profiles.Count && profile == null)
    {
       if (profiles[p].VirtualPath != null &&
           profiles[p].VirtualPath.Equals(virtualPath))
       {
           profile = profiles[p];
       }
       else
       {
           p++;
       }
    }
    if (profile == null)
    {
       // Adds a new empty profile to the Server:
       profile = m_VirtualUIConfig.Profiles.Add();
       // Set the VirtualPath property (this value must be unique).
       profile.VirtualPath = "demoapp";
    }
    // Set basic profile properties:
    // - VirtualPath must be unique.
    // - UserName and Password must be a valid Windows Account
    //   in the VirtualUI server machine:
    profile.Name = "Demo Application";
    profile.FileName = @"C:\path_to_app\demo.exe";
    profile.UserName = "windows_user";
    profile.Password = "user_password";
    profile.ProfileKind = ProfileKind.PROFILE_APP;
    //If needed, you can set other properties
    //like Arguments, StartDir, etc.

    // Set profile icon, in this case from external file
    // (you can also extract the application icon, convert
    // to PNG, and pass to IconToBase64):
    Bitmap icon = (Bitmap)Image.FromFile("demo_icon.png");
    profile.IconData = ServerUtils.IconToBase64(icon);

    // Save changes:
    m_VirtualUIConfig.Save();

}

 

Changing Thinfinity VirtualUI Server manager’s tabs visibility

You can also programmatically set the visibility of the tabs in the Thinfinity VirtualUI Server manager (in particular, the one with the application profiles).

The code presented below (Delphi) shows how:

procedure TFormMain.hideAppTabButtonClick(Sender: TObject);
begin
  // This hides the "Applications" tab in the VirtualUI Server Manager:
  Server.HideSection(SRVSEC_Applications);

  // Save changes:
  Server.Save;
end;

The C# version is as follows:

private void hideAppTabButton_Click(object sender, EventArgs e)
{
    // This hides the "Applications" tab in the VirtualUI Server Manager:
    m_VirtualUIConfig.HideSection(ServerSection.SRVSEC_APPLICATIONS);

    // Save changes:
    m_VirtualUIConfig.Save();
}

As a final comment, it must be clarified that in order to save the profiles in the configuration, writing permission on that directory is required.

Have any questions? Contact us at support@cybelesoft.com or leave a message on this same post.

Related Posts

Leave a comment