Abstractions.WindowsApi.pInvokes.GetUserName C# (CSharp) Method

GetUserName() public static method

public static GetUserName ( int sessionId ) : string
sessionId int
return string
        public static string GetUserName(int sessionId)
        {
            uint bytes = 0;
            IntPtr userInfo = IntPtr.Zero;

            bool result = SafeNativeMethods.WTSQuerySessionInformation(SafeNativeMethods.WTS_CURRENT_SERVER_HANDLE, sessionId, SafeNativeMethods.WTS_INFO_CLASS.WTSUserName, out userInfo, out bytes);
            if (!result)
            {
                LibraryLogging.Error("GetUserName({1}) WTSQuerySessionInformation WTSUserName Error:{0}", LastError(), sessionId);
            }
            string userName = Marshal.PtrToStringAnsi(userInfo);
            SafeNativeMethods.WTSFreeMemory(userInfo);

            return userName;
        }