I have a tool which I use to programmatically create local user accounts as follows:
The account is created fine but at at this point the User Profile does not exists (no HKEY CURRENT USER, no Documents & 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:
http://support.microsoft.com/kb/196070/en-us
So I added the code as follows:
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 & settings" for the new account.
Anyone have any clues as to what I am doing wrong?
Any help would be much appreciated.
Thanks,
Code:
DirectoryEntry NewUser = dirEntryLocalMachine.Children.Add("UserName", "user");
NewUser.Invoke("SetPassword", new object[] { "Passsord" });
NewUser.Invoke("Put", new object[] { "Description", "Description" });
NewUser.CommitChanges();
The account is created fine but at at this point the User Profile does not exists (no HKEY CURRENT USER, no Documents & 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:
http://support.microsoft.com/kb/196070/en-us
So I added the code as follows:
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);
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 & settings" for the new account.
Anyone have any clues as to what I am doing wrong?
Any help would be much appreciated.
Thanks,