title: How to force Windows to create the running user's profile directory
body: <p>I am having an issue with a process being run, where the profile directory of the process' user has not yet been created.</p>
  
  <p>To explain, here are the details of how this is happening:</p>
  
  <p>We run a large distributed server grid, and are using (parts of) DataSynapse to execute processes on this grid.  For those familiar with DataSynapse, the Engine is configured to run the particular service with "RunAs", where we use a certain AD domain service account for the service processes.  I believe the problem is that DataSynapse, when running the process under "runas", does not set the <code>LoadUserProfile</code> flag (nor should it).  Whatever the precise reason, if the "runas" service account (and AD domain account) has never logged on to some of the grid machines, then those machines will not have the user profile directory for the account.</p>
  
  <p>For those not familiar with DataSynapse, here is a more generic explanation.  On each machine on the grid, there is a process running, I'll call it <code>dsService</code>, and it runs under the credentials of the local machine's system account (or some similar account with elevated credentials).  The process <code>dsService</code> will spawn a child process, say <code>childProcess</code>, but it runs <code>childProcess</code> under the credentials of our AD domain account, which I'll call <code>serviceUser</code>.  There are thousands of machines on the grid, and typically they are never logged on to manually.  In particular, the profile directory <code>C:\users\serviceUser</code> may not initially exist.  Once it is created once, there are not further issues.  But if new nodes are added to the grid, typically they will not have the <code>C:\users\serviceUser</code> initially.  The problem is that when the <code>dsService</code> spawns <code>childProcess</code>, <code>C:\users\serviceUser</code> does not get created, and we need it.</p>
  
  <p>I <em>believe</em> that this is because <code>dsService</code> does not set the <code>LoadUserProfile</code> flag to true when spawning <code>childProcess</code>, though I am not certain.</p>
  
  <p>In any event, <code>childProcess</code> is a (.net) process (running as <code>serviceUser</code>) under our control, and <strong>I would like to know if there is a way (in C#) that <code>childProcess</code> can force the OS to create the running user's profile directory</strong> <code>C:\users\serviceUser</code> when it determines that it does not yet exist?</p>
  
  <p>Edit:
  Experimentation has confirmed that if one starts a process under another user ID, and the user's profile directory is not there (more specifically, if the user's <em>local profile</em> has not been created yet - merely deleting a pre-existing profile directory creates a different situation, one we're not interested in anyway), then (1) the profile directory (and one presumes, the local profile) gets created if the process is started with the <code>LoadUserProfile</code> set to true; and (2)  the profile directory (and one presumes, the local profile) does NOT get created if the process is started with the <code>LoadUserProfile</code> set to false.  This makes sense, and is as one would expect.</p>
  
  <p>Related post: stackoverflow.com/q/9008742/1082063</p>