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 "";
}