title: Electron Squirrel.Windows: How can I remove local app data on uninstall?
body: <p>Currently I have an installer built with Squirrel.Windows. On uninstall, the application directory under: </p>
  
  <pre><code>C:\Users\Me\AppData\Local\MyApplicationDirectory
  </code></pre>
  
  <p>remains. I have tried using <a href="https://www.npmjs.com/package/rimraf" rel="nofollow noreferrer">rimraf</a> under the the <code>--squirrel-uninstall</code> hook to remove the directory, but it fails because the files are in use.</p>
  
  <p>Here is what I have that is not working:</p>
  
  <pre><code>case '--squirrel-uninstall':
      var myLocalAppData = "C:\\Users\\Me\\AppData\\Local\\MyApplication";
      rimraf(myLocalAppData);
      app.quit();
  </code></pre>
  
  <p>I have tried the following to no avail:</p>
  
  <ol>
  <li>Using a <code>setTimeout()</code> to delay the <code>rimraf(myLocalAppData)</code> call</li>
  <li>Using the <code>maxBusyTries</code> param in the rimraf options to continue retrying for 10 seconds if a <code>EBUSY</code>, <code>ENOTEMPTY</code>, or <code>EPERM</code> error code is encountered when trying to clean up the directory</li>
  <li>Running <code>app.exit()</code> before the <code>rimraf(myLocalAppData)</code></li>
  </ol>
  
  <p>I know the NSIS installer provided by <a href="https://www.npmjs.com/package/electron-builder" rel="nofollow noreferrer">electron-builder</a> properly cleans up the app data directory, but I cannot use it as I need a MSI to support machine wide installations via Group Policy Management. </p>
  
  <p>Any help is appreciated!</p>