2012-03-07 33 views
0

即時通訊目前使用WFAPI確定從C#當在citrix會話中運行時,C#用於確定客戶端IP地址?

[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; 
} 

Citrix會話的客戶端IP地址WFAPI.DLL/WFAPI64.DLL似乎可以在我有機會獲得Citrix環境。 有沒有人有更好的方法來做到這一點?
還有誰知道如何確定過程是否實際上在思傑環境中運行?

回答

2

沒有你在做什麼很好。 WFAPI是獲取這類信息的最佳途徑之一。

瞭解會話是否是Citrix會話只是您正在做的事情的擴展。如果你看一下WFQuerySessionInformation的WFAPI參考:

http://community.citrix.com/download/attachments/37388956/WFAPI_SDK_Documentation.pdf

看WFInfoClass值表。您將看到許多參數的標籤爲「3」,表明它們僅在ICA會話中被調用時可用。因此,您可以使用其中一種方法調用WFQuerySessionInformation,如果它返回false,則說明您未在Citrix會話中運行。您目前正在執行的IP地址查詢是這些屬性之一,因此,當您的「ok」變量爲false時,您不在Citrix會話中。

其他感興趣的東西,微軟提供的WTS API與WFAPI非常相似,並且大部分都是相同的東西。但是,WFAPI具有可與XenDesktop和XenApp配合使用的優勢,而WTS API只能與XenApp配合使用。

Regards, Donovan