コード例 #1
0
        private static string GetHostInternal()
        {
            try
            {
                var host = EnvironmentHelpers.GetMachineName();
                if (!string.IsNullOrEmpty(host))
                {
                    return(host);
                }

                return(EnvironmentHelpers.GetEnvironmentVariable("COMPUTERNAME"));
            }
            catch (InvalidOperationException)
            {
            }
            catch (System.Security.SecurityException)
            {
                // We may get a security exception looking up the machine name
                // You must have Unrestricted EnvironmentPermission to access resource
            }

            return(null);
        }