/// <summary> /// Return the username for the current user /// </summary> /// <returns></returns> public static string CurrentUserName() { string CurrentUserNameRet = default; MemPtr lps = new MemPtr(); int cb = 10240; lps.ReAlloc(10240L); lps.ZeroMemory(); if (GetUserName(lps.Handle, ref cb)) { CurrentUserNameRet = lps.ToString(); } else { CurrentUserNameRet = null; } lps.Free(); return(CurrentUserNameRet); }
/// <summary> /// Return the current user's full display name /// </summary> /// <param name="type"></param> /// <returns></returns> public static string CurrentUserFullName(ExtendedNameFormat type = ExtendedNameFormat.NameDisplay) { string CurrentUserFullNameRet = default; MemPtr lps; int cb = 10240; lps = new MemPtr(10240L); lps.ZeroMemory(); if (GetUserNameEx(type, lps.Handle, ref cb)) { CurrentUserFullNameRet = lps.ToString(); } else { CurrentUserFullNameRet = null; } lps.Free(); return(CurrentUserFullNameRet); }