Im currently using WFAPI to determine the client ip address of a citrix session from C#
[StructLayout(LayoutKind.Sequential)]
internal struct WF_CLIENT_ADDRESS {
public int AddressFamily;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[] Address;
}
[DllImport("WFAPI.dll", EntryPoint = "WFFreeMemory")]
private static extern void WFFreeMemory(IntPtr pMemory);
[DllImport("WFAPI.dll", EntryPoint = "WFQuerySessionInformationA")]
private static extern bool WFQuerySessionInformation(IntPtr hServer,
int iSessionId, int infotype, out IntPtr ppBuffer, out int pBytesReturned);
const int ClientAddress = 14;
const int CurrentSession = -1;
static readonly IntPtr CurrentServer = IntPtr.Zero;
public static string GetClientAddress() {
IntPtr addr;
int returned;
bool ok = WFQuerySessionInformation(CurrentServer, CurrentSession,
ClientAddress, out addr, out returned);
if (!ok) return null;
WF_CLIENT_ADDRESS obj = new WF_CLIENT_ADDRESS();
obj = (WF_CLIENT_ADDRESS)Marshal.PtrToStructure(addr, obj.GetType());
string clientAdress =
obj.Address[2] + "." + obj.Address[3] + "." +
obj.Address[4] + "." + obj.Address[5];
WFFreeMemory(addr);
return clientAdress;
}
WFAPI.DLL/WFAPI64.DLL seems to be available at the citrix environments that I have access to.
Does anyone have a better way to do this?
And does anyone know how to determine if the process is in fact running in a citrix environment or not?