取得操作系统用户名称:
public async static Task<string> GetDisplayNameAsync() { string displayName = await UserInformation.GetDisplayNameAsync(); if (string.IsNullOrEmpty(displayName)) displayName = DefaultDisplayName; return displayName; }
取得当前机器名称:
public static string GetMachineName() { IReadOnlyList<HostName> hostNames = NetworkInformation.GetHostNames(); HostName hostName = hostNames.FirstOrDefault(x => x.Type == HostNameType.DomainName); if (hostName == null) return DefaultMachineName; return hostName.DisplayName; }
时间: 2024-10-15 08:58:36