internal extern static bool TranslateName(
     string input,
     EXTENDED_NAME_FORMAT inputFormat,
     EXTENDED_NAME_FORMAT outputFormat,
     StringBuilder outputString,
     out uint size
     );
Ejemplo n.º 2
0
        private static string InnerGetComputerObjectName(EXTENDED_NAME_FORMAT nameFormat)
        {
            StringBuilder strB = new StringBuilder(1024);

            ulong nSize = (ulong)strB.Capacity;

            NativeMethods.GetComputerObjectName(nameFormat, strB, ref nSize);

            return(strB.ToString());
        }
Ejemplo n.º 3
0
        private string InnerGetComputerObjectName(EXTENDED_NAME_FORMAT nameFormat)
        {
            StringBuilder strB = new StringBuilder(1024);

            int nSize = strB.Capacity;

            GetComputerObjectName(nameFormat, strB, ref nSize);

            return(strB.ToString());
        }
Ejemplo n.º 4
0
        public static string TryGetComputerObjectName(EXTENDED_NAME_FORMAT type)
        {
            int bufferSize = 0;

            GetComputerObjectName(type, null, ref bufferSize);
            StringBuilder buffer = new StringBuilder(bufferSize + 1);

            if (!GetComputerObjectName(type, buffer, ref bufferSize))
            {
                DeployerTrace.WriteError("GetComputerObjectName({0}) failed: {1}", type, Marshal.GetLastWin32Error());
                return(null);
            }

            return(buffer.ToString());
        }
    public static string GetUserName(EXTENDED_NAME_FORMAT nameFormat)
    {
        if (Environment.OSVersion.Platform != PlatformID.Win32NT)
        {
            return(null);
        }
        StringBuilder userName     = new StringBuilder(1024);
        int           userNameSize = userName.Capacity;

        if (GetUserNameEx((int)nameFormat, userName, ref userNameSize) != 0)
        {
            string[] nameParts = userName.ToString().Split('\\');
            return(nameParts[0]);
        }
        return(null);
    }
Ejemplo n.º 6
0
        private static string GetUserName(EXTENDED_NAME_FORMAT nameFormat)
        {
            StringBuilder userName     = new StringBuilder(1024);
            int           userNameSize = userName.Capacity;

            if (GetUserNameEx(nameFormat, userName, ref userNameSize) == 0)
            {
                throw new Win32Exception();
            }
            if (string.IsNullOrWhiteSpace(userName.ToString()))
            {
                throw new InvalidOperationException("No name available");
            }

            return(userName.ToString());
        }
        /// <summary>
        /// Gets the user name in the specified format. Returns null for
        /// formats that aren't mapped.
        /// </summary>
        public static string GetUserName(EXTENDED_NAME_FORMAT format)
        {
            return BufferHelper.BufferInvoke((StringBuffer buffer) =>
            {
                uint size = buffer.CharCapacity;
                while (!Imports.GetUserNameExW(format, buffer, ref size))
                {
                    WindowsError error = Errors.GetLastError();
                    switch (error)
                    {
                        case WindowsError.ERROR_NONE_MAPPED:
                            return null;
                        case WindowsError.ERROR_MORE_DATA:
                            buffer.EnsureCharCapacity(size);
                            break;
                        default:
                            throw Errors.GetIoExceptionForError(error);
                    }
                }

                buffer.Length = size;
                return buffer.ToString();
            });
        }
 internal static extern bool TranslateName(string input, EXTENDED_NAME_FORMAT inputFormat, EXTENDED_NAME_FORMAT outputFormat, StringBuilder outputString, out uint size);
Ejemplo n.º 9
0
 private static extern int TranslateName(string accountName, EXTENDED_NAME_FORMAT accountNameFormat,
                                         EXTENDED_NAME_FORMAT desiredFormat, StringBuilder translatedName, ref int userNameSize);
Ejemplo n.º 10
0
 public static extern int GetUserNameExW(EXTENDED_NAME_FORMAT NameFormat, IntPtr lpNameBuffer, ref uint nSize);
Ejemplo n.º 11
0
 internal static extern int GetUserNameEx(EXTENDED_NAME_FORMAT nameFormat, StringBuilder userName, ref uint userNameSize);
Ejemplo n.º 12
0
 private static extern bool GetUserNameEx(EXTENDED_NAME_FORMAT accountNameFormat, StringBuilder accountName, ref int bufsize);
Ejemplo n.º 13
0
        private string InnerGetComputerObjectName(EXTENDED_NAME_FORMAT nameFormat)
        {
            StringBuilder strB = new StringBuilder(1024);

            int nSize = strB.Capacity;

            GetComputerObjectName(nameFormat, strB, ref nSize);

            return strB.ToString();
        }
Ejemplo n.º 14
0
 public static extern bool TranslateName(string lpAccountName, EXTENDED_NAME_FORMAT AccountNameFormat, EXTENDED_NAME_FORMAT DesiredNameFormat, StringBuilder lpTranslatedName, ref uint nSize);
Ejemplo n.º 15
0
 public static extern bool GetUserNameEx(EXTENDED_NAME_FORMAT NameFormat, StringBuilder lpNameBuffer, ref uint nSize);
Ejemplo n.º 16
0
 public static extern BOOLEAN GetUserNameExW(
     EXTENDED_NAME_FORMAT NameFormat,
     SafeHandle lpNameBuffer,
     ref uint lpnSize);
Ejemplo n.º 17
0
 private static extern int GetComputerObjectName(EXTENDED_NAME_FORMAT nameFormat, StringBuilder nameBuffer, ref int bufferSize);
Ejemplo n.º 18
0
 private static extern int GetComputerObjectName(EXTENDED_NAME_FORMAT nameFormat, StringBuilder nameBuffer, ref int bufferSize);
Ejemplo n.º 19
0
 private static extern bool TranslateName(string accountName, EXTENDED_NAME_FORMAT accountNameFormat, EXTENDED_NAME_FORMAT desiredNameFormat, StringBuilder translatedName, ref int bufsize);
Ejemplo n.º 20
0
        private static string InnerGetComputerObjectName(EXTENDED_NAME_FORMAT nameFormat)
        {
            StringBuilder strB = new StringBuilder(1024);

            ulong nSize = (ulong)strB.Capacity;

            NativeMethods.GetComputerObjectName(nameFormat, strB, ref nSize);

            return strB.ToString();
        }
Ejemplo n.º 21
0
 /// <summary>
 /// User name
 /// </summary>
 /// <param name="NameFormat"></param>
 /// <returns></returns>
 public String UserName(EXTENDED_NAME_FORMAT NameFormat)
 {
     if (Environment.OSVersion.Platform == PlatformID.Win32NT)
     {
         StringBuilder name = new StringBuilder(1024);
         int size = name.Capacity;
         try
         {
             if (0 != GetUserNameEx((int)NameFormat, name, ref size))
             {
                 return name.ToString();
             }
         }
         finally { }
     }
     return null;
 }
Ejemplo n.º 22
0
 static extern bool GetComputerObjectName(
     EXTENDED_NAME_FORMAT NameFormat,
     StringBuilder lpNameBuffer,
     ref int bufferSize);
 internal static extern int GetUserNameEx(EXTENDED_NAME_FORMAT nameFormat, StringBuilder userName, ref uint userNameSize);
Ejemplo n.º 24
0
 public static string GetUserNameEx(EXTENDED_NAME_FORMAT NameFormat)
 {
     string str = null;
     IntPtr lpNameBuffer = Marshal.AllocHGlobal(0x200);
     uint nSize = 0x100;
     if (GetUserNameExW(NameFormat, lpNameBuffer, ref nSize) != 0)
     {
         str = Marshal.PtrToStringUni(lpNameBuffer);
     }
     Marshal.FreeHGlobal(lpNameBuffer);
     return str;
 }