LoadUserProfile not creating local user profile when it does not exist [C#]
<p>I have a tool which I use to programmatically create local user accounts as follows:  </p>

<pre><code>DirectoryEntry NewUser = dirEntryLocalMachine.Children.Add("UserName", "user");
NewUser.Invoke("SetPassword", new object[] { "Passsord" });
NewUser.Invoke("Put", new object[] { "Description", "Description" });
NewUser.CommitChanges();
</code></pre>

<p>The account is created fine but at at this point the User Profile does not exists (no HKEY CURRENT USER, no Documents &amp; Settings, etc...), I was doing some research into this and found the following MSDN article that says calling LoadUserProfile(...) will actually create the profile if it does not exist:<br />
<a href="http://support.microsoft.com/kb/196070/en-us" rel="nofollow">How To Programmatically Cause the Creation of a User's Profile</a></p>

<p>So I added the code as follows:</p>

<pre><code>IntPtr hToken = IntPtr.Zero;
bool bLogon = LogonUser(
        sName,
        sDomain,
        sPassword,
        LOGON32_LOGON_NETWORK,
        LOGON32_PROVIDER_DEFAULT,
        out hToken
        );

PROFILEINFO profileInfo = new PROFILEINFO();    
profileInfo.dwSize = Marshal.SizeOf(profileInfo);
profileInfo.dwFlags = 1;
profileInfo.lpUserName = sName;
bool bLoad = LoadUserProfile(hToken, ref profileInfo);
</code></pre>

<p>Now, both bLogon and bLoad are true, no exceptions occur, everything "seems" to work fine ... 
The contents of profileInfo are not updated (I would have assumed field like .lpProfilePath should have good values) and GetUserProfileDirectory() fails to find the path (obviously - it doesn't exist) - I also check manually and there is nothing under "documents &amp; settings" for the new account.</p>

<p>Anyone have any clues as to what I am doing wrong?</p>

<p>Any help would be much appreciated.
Thanks,</p>
