title: Inno Setup - How to replace UserName with string
body: <p>first attempt at posting this question was with severe jet lag.  This re-edit of the question I only have the associated sleep deprivation...</p>
  
  <p>I want to know the best way to use the installer to capture path information and then remove any reference to the user profile.</p>
  
  <p>My program is designed to run from a central network location.  To reduce network traffic some files are copied to a local drive, eg. AppData\MyProg\  </p>
  
  <p>I use a file browse dialogue so the person installing can specify the location:</p>
  
  <pre><code>pg_LocalPaths := CreateInputDirPage(pg_CentralPaths.id,
  'Confirm File Locations For User Settings', 'To improve user experience these locations should be off the network.',
  'Default Locations are:', False, 'New Folder');
       // Add file browswer item (with an empty caption)
          pg_LocalPaths.Add('Supporting files will be copied here by the application:');
          pg_LocalPaths.Add('User settings (for a single user) will be saved here:');
  
       // Set initial value 
          pg_LocalPaths.Values[0] := GetPreviousData('pg_LocalPaths0', ExpandConstant('{userappdata}\{#pFolder}'));
          pg_LocalPaths.Values[1] := GetPreviousData('pg_LocalPaths1', ExpandConstant('{userappdata}\{#pFolder}'));
  </code></pre>
  
  <p>During install the local drive location is specified and stored in a config file.  </p>
  
  <p>An issue that I failed to predict is that when the program is installed, the path in the config file is defined for a single user, namely the user performing the install.  In practice any user should be able to run the program...</p>
  
  <p>To get the correct path for any given user, my software looks for a string "{UserName}" and replaces it with: Environ(UserName)</p>
  
  <pre><code>MyPath = Replace(MyPath, "{UserName}", Environ(UserName))
  </code></pre>
  
  <p>So, for example, in the installer I need to replace: </p>
  
  <pre><code>C:\Users\My Name\My Program   OR     C:\Users\My Admin\My Program   
  </code></pre>
  
  <p>with something like:</p>
  
  <pre><code>C:\Users\\{UserName}\My Program
  </code></pre>
  
  <p>I alreay have this working in My Program but I am not sure of the best way to get it working in Inno... My inital thought was to write the config file like this:</p>
  
  <p>StringChangeEx(MyPath, "My Name", "{UserName}", True)</p>
  
  <p>Would like some perspective on this, not sure how to get it working for all situations.</p>
  
  <p>Cheers,</p>