title: Uninstalling application written in c# using setup and deployment and Installer class
body: <p>my program installs my custom service and register it. Now what I am trying to do is to unregister the service and delete all files after uninstall. I am using Visual Studio and Setup and Deployment and the Installer class, I have overridden a few methods that I am presenting below:</p>
  
  <pre><code>protected override void OnAfterUninstall(IDictionary savedState)
  {
      base.OnAfterUninstall(savedState);
      string directory = "C:\\Program Files (x86)\\MyService\\";
      if (System.IO.Directory.Exists(directory))
      {
          string[] files = System.IO.Directory.GetFiles(directory);
          foreach (string file in files)
          {
              System.IO.File.Delete(file);
          }
          System.IO.Directory.Delete(directory);
      }
  }
  
  protected override void OnBeforeUninstall(IDictionary savedState)
  {
      base.OnBeforeUninstall(savedState);
      string path = "-u \"C:\\Program Files (x86)\\MyService\\AA_service.exe\"";
      ProcessStartInfo startInfo = new ProcessStartInfo();
      startInfo.CreateNoWindow = false;
      startInfo.UseShellExecute = false;
      startInfo.FileName = "C:\\Program Files (x86)\\MyService\\InstallUtil.exe";
      startInfo.WindowStyle = ProcessWindowStyle.Hidden;
      startInfo.Arguments = path;
  
  
      Process.Start(startInfo);
  
  }
  </code></pre>
  
  <p>It does not unregister service and it does not delete application folder. Can anyone suggest me what am I doing wrong?</p>
  
  <p>//edit</p>
  
  <p>now it is trying to remove files but I am getting access denied error on uninstall. Files I am trying to delete are .exe, .dll and some others</p>