C#应用程序需要在Citrix环境中引用远程工作站 [英] C# application needs to reference remote workstation in Citrix environment

查看:179
本文介绍了C#应用程序需要在Citrix环境中引用远程工作站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#独立的Windows窗体应用程序.它连接到后台系统,该后台系统在身份识别过程中需要工作站名称.我正在使用Environment.MachineName来获取它.但是,使用此应用程序的客户有时会在Citrix环境下运行它,当他们这样做时,他们希望它引用远程计算机名称,而不是引用安装该计算机的计算机.我以前从未编码过类似的代码,并且对Citrix不熟悉(所以我刚开始飞行).如何获得远程计算机名称?任何想法都非常感谢.

I have a C# standalone Windows Forms application. It connects to a back office system that requires the workstation name as part of the identification process. I'm using Environment.MachineName to get this. However the customer using this application will occasionally run it under a Citrix environment and, when they do, they want it to reference the remote machine name, not the machine it is installed on. I have never coded anything like this before, and am unfamiliar with Citrix (so I'm off to a flying start). How do I get the remote machine name? Any ideas hugely appreciated.

预先表示感谢.

推荐答案

在Citrix系统上,有一个名为CLIENTNAME的环境变量,该变量具有用户从中连接到Citrix的计算机的名称.这只是一个普通的Windows环境变量,因此您可以使用Environment.GetEnvironmentVariable来读取它.

On a Citrix systems there's an Environment Variable called CLIENTNAME that has the name of the machine that the user is connecting to Citrix from. It's just a regular Windows environment variable so you can use Environment.GetEnvironmentVariable to read it.

您可以像这样快速而肮脏地做某事:

You could do something quick and dirty like this:

var workstationName = Environment.GetEnvironmentVariable("CLIENTNAME") ?? Environment.MachineName;

对于更强大的功能,Citrix环境还具有用于标识Citrix会话的SESSIONNAME变量.这两个变量的并存可能是在Citrix会话中运行的更好测试.

For something a little more robust, a Citrix environment also has a SESSIONNAME variable that identifies the Citrix session. The presence of these two variables together is probably a better test for running in a Citrix session.

因此您可以执行以下操作:

So you could do something like this:

public bool IsCitrixSession() {
    return Environment.GetEnvironmentVariable("CLIENTNAME") != null
        && Environment.GetEnvironmentVariable("SESSIONNAME") != null;
}

public string GetWorkstationName()
{
    return IsCitrixSession() ? Environment.GetEnvironmentVariable("CLIENTNAME")
                             : Environment.MachineName;
} 

这篇关于C#应用程序需要在Citrix环境中引用远程工作站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆