internal static string GetComputerName(ComputerNameFormat nameType) { int size = 0; if (!GetComputerNameEx(nameType, null, ref size)) { int error = Marshal.GetLastWin32Error(); if (error != 0xea) { throw Fx.Exception.AsError(new Win32Exception(error)); } } if (size < 0) { Fx.AssertAndThrow("GetComputerName returned an invalid length: " + size); } StringBuilder lpBuffer = new StringBuilder(size); if (!GetComputerNameEx(nameType, lpBuffer, ref size)) { int num3 = Marshal.GetLastWin32Error(); throw Fx.Exception.AsError(new Win32Exception(num3)); } return(lpBuffer.ToString()); }
internal static string GetComputerName(ComputerNameFormat nameType) { int size = 0; if (!GetComputerNameEx(nameType, null, ref size)) { int error = Marshal.GetLastWin32Error(); if (error != 0xea) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(error)); } } if (size < 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("GetComputerNameReturnedInvalidLenth", new object[] { size }))); } StringBuilder lpBuffer = new StringBuilder(size); if (!GetComputerNameEx(nameType, lpBuffer, ref size)) { int num3 = Marshal.GetLastWin32Error(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(num3)); } return(lpBuffer.ToString()); }
internal static string GetComputerName(ComputerNameFormat nameType) { int num = 0; if (!UnsafeNativeMethods.GetComputerNameEx(nameType, null, out num)) { int lastWin32Error = Marshal.GetLastWin32Error(); if (lastWin32Error != 234) { throw Fx.Exception.AsError(new Win32Exception(lastWin32Error)); } } if (num < 0) { Fx.AssertAndThrow(string.Concat("GetComputerName returned an invalid length: ", num)); } StringBuilder stringBuilder = new StringBuilder(num); if (UnsafeNativeMethods.GetComputerNameEx(nameType, stringBuilder, out num)) { return stringBuilder.ToString(); } else { int lastWin32Error1 = Marshal.GetLastWin32Error(); throw Fx.Exception.AsError(new Win32Exception(lastWin32Error1)); } }
internal static string GetComputerName(ComputerNameFormat nameType) { int length = 0; if (!GetComputerNameEx(nameType, null, ref length)) { int error = Marshal.GetLastWin32Error(); if (error != ERROR_MORE_DATA) { throw Fx.Exception.AsError(new System.ComponentModel.Win32Exception(error)); } } if (length < 0) { Fx.AssertAndThrow("GetComputerName returned an invalid length: " + length); } StringBuilder stringBuilder = new StringBuilder(length); if (!GetComputerNameEx(nameType, stringBuilder, ref length)) { int error = Marshal.GetLastWin32Error(); throw Fx.Exception.AsError(new System.ComponentModel.Win32Exception(error)); } return(stringBuilder.ToString()); }
internal static string GetComputerName(ComputerNameFormat nameType) { int num = 0; if (!UnsafeNativeMethods.GetComputerNameEx(nameType, null, out num)) { int lastWin32Error = Marshal.GetLastWin32Error(); if (lastWin32Error != 234) { throw Fx.Exception.AsError(new Win32Exception(lastWin32Error)); } } if (num < 0) { Fx.AssertAndThrow(string.Concat("GetComputerName returned an invalid length: ", num)); } StringBuilder stringBuilder = new StringBuilder(num); if (UnsafeNativeMethods.GetComputerNameEx(nameType, stringBuilder, out num)) { return(stringBuilder.ToString()); } else { int lastWin32Error1 = Marshal.GetLastWin32Error(); throw Fx.Exception.AsError(new Win32Exception(lastWin32Error1)); } }
// GetComputerNameEx function // http://msdn.microsoft.com/en-us/library/windows/desktop/ms724301(v=vs.85).aspx public static string GetComputerName(ComputerNameFormat format) { StringBuilder builder = new StringBuilder(260); int size = builder.Capacity; if (!NativeMethods.GetComputerNameEx(format, builder, ref size)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } return(builder.ToString()); }
/// <summary> /// Get the computer name in the specified format. /// </summary> public static string GetComputerName(ComputerNameFormat format) { return(BufferHelper.BufferInvoke((StringBuffer buffer) => { uint size = buffer.CharCapacity; while (!Imports.GetComputerNameExW(format, buffer, ref size)) { Error.ThrowIfLastErrorNot(WindowsError.ERROR_MORE_DATA); buffer.EnsureCharCapacity(size); } buffer.Length = size; return buffer.ToString(); })); }
internal static string GetComputerName(ComputerNameFormat nameType) { int size = 0; if (!GetComputerNameEx(nameType, null, ref size)) { int error = Marshal.GetLastWin32Error(); if (error != 0xea) { throw Fx.Exception.AsError(new Win32Exception(error)); } } if (size < 0) { Fx.AssertAndThrow("GetComputerName returned an invalid length: " + size); } StringBuilder lpBuffer = new StringBuilder(size); if (!GetComputerNameEx(nameType, lpBuffer, ref size)) { int num3 = Marshal.GetLastWin32Error(); throw Fx.Exception.AsError(new Win32Exception(num3)); } return lpBuffer.ToString(); }
internal static string GetComputerName(ComputerNameFormat nameType) { int length = 0; if (!GetComputerNameEx(nameType, null, ref length)) { int error = Marshal.GetLastWin32Error(); if (error != ERROR_MORE_DATA) { throw Fx.Exception.AsError(new System.ComponentModel.Win32Exception(error)); } } if (length < 0) { Fx.AssertAndThrow("GetComputerName returned an invalid length: " + length); } StringBuilder stringBuilder = new StringBuilder(length); if (!GetComputerNameEx(nameType, stringBuilder, ref length)) { int error = Marshal.GetLastWin32Error(); throw Fx.Exception.AsError(new System.ComponentModel.Win32Exception(error)); } return stringBuilder.ToString(); }
internal static extern bool SetComputerNameExA(ComputerNameFormat nameType, string computerName);
public static extern bool GetComputerNameExW( ComputerNameFormat NameType, SafeHandle lpBuffer, ref uint lpnSize);
private static extern bool GetComputerNameEx(ComputerNameFormat nameType, StringBuilder lpBuffer, out int size);
internal static string GetComputerName (ComputerNameFormat nameType) { throw new NotImplementedException (); }
internal static string GetComputerName(ComputerNameFormat nameType) { throw new NotImplementedException(); }
private static extern bool GetComputerNameEx([In] ComputerNameFormat nameType, [In][Out] StringBuilder lpBuffer, [In][Out] ref int size);
internal static extern bool GetComputerNameEx( ComputerNameFormat NameType, [Out] StringBuilder lpBuffer, ref int lpnSize);
internal static string GetComputerName(ComputerNameFormat nameType) { return System.Runtime.Interop.UnsafeNativeMethods.GetComputerName(nameType); }
private static extern bool GetComputerNameEx([In] ComputerNameFormat nameType, [In, Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpBuffer, [In, Out] ref int size);