Abstractions.WindowsApi.pInvokes.CreateUserProfileDir C# (CSharp) Method

CreateUserProfileDir() public static method

calls API CreateProfile an empty string on error a null string on already exists a string on success
public static CreateUserProfileDir ( IntPtr hToken, string username ) : string
hToken System.IntPtr
username string
return string
        public static string CreateUserProfileDir(IntPtr hToken, string username)
        {
            StringBuilder path = new StringBuilder(260);
            uint size = Convert.ToUInt32(path.Capacity);
            uint hResult = 0;

            using (System.Security.Principal.WindowsIdentity i = new System.Security.Principal.WindowsIdentity(hToken))
            {
                hResult = SafeNativeMethods.CreateProfile(i.Owner.Value, username, path, size);
            }
            if (hResult == 2147942583)
            {
                LibraryLogging.Error("CreateProfile already exists:{0}", LastError());
                return null;
            }
            else if (hResult == 0)
            {
                return path.ToString();
            }
            else
            {
                LibraryLogging.Error("CreateProfile error:{0} {1}", hResult, LastError());
            }

            return "";
        }