For some project I need to:
Dynamically create local user account (for this I'm using UserPrincipal class from .NET framework)
Impersonate to that user (I wrote some classes that calls native LogonUser (advapi32.dll)
Use DPAPI to encrypt some user data. I also have some classes that calls native CryptProtectData and CryptUnprotectData (crypt32.dll)
The problem here is that when dynamically creating user, user specific folders are not created, even when I call LogonUser.
Since DPAPI will look for those folders, and the folders are not there, the call will fail.
Now, if I manually perform user login, those folders will be created, and after that all is good. But, I need a way to create those folders automatically, without performing manual login.
Is there a way to do that?
I found out that there is function LoadUserProfile in userenv.dll. This is what I was looking for.
Now, all works as expected.