title: Inno Setup run/execute code as another user
body: <p>Much as it is possible to use <code>ExecAsOriginalUser</code> to run something using the starting/logged in user's credentials, is there a command or way to run a particular piece of code as a specific user?</p>
  
  <p>To explain further, I am writing the computer name into a log on a file share at the end of installation. This works perfectly as long as not installing using a local Administrator account which does not have a matching local Administrator account on the server. Therefore, what I need to do is have the particular bit of code that writes to the log execute as a specific user account, which I have the credentials for, that I know exists on the server.</p>
  
  <p>The code I am using is as follows:</p>
  
  <pre class="lang-pascal prettyprint-override"><code>{ Auto audit the computer name }
  procedure AutoAudit();
  var
    strComputerName: TArrayOfString;
    strAutoAuditFile: String;
  begin
    strAutoAuditFile := '\\' + ClientConnectionPage.Values[0] + '\Audit\Client Audit.txt';
    SetArrayLength(strComputerName, 1);
    strComputerName[0] :=
      ExpandConstant('{computername} ') + GetDateTimeString('dd/mm/yyyy hh:mm', '/', ':');
    SaveStringsToFile(strAutoAuditFile, strComputerName, True);
  end;
  </code></pre>
  
  <p>So, what I need is a way of executing the <code>SaveStringsToFile</code> function as another user.</p>
  
  <p>I have thought of a rather messy way to do this, which would involve testing for an available drive letter, mapping a drive using the account credentials, writing to the file and then disconnecting the drive. However, I am hoping there is a more elegant way to do this?</p>