title: Determine whether assembly is a gui application
body: <p>I am trying to determine whether a C# assembly is a GUI or a Console application in order to build a tool which will automatically recreate lost short cuts.</p>
  
  <p>Currently, I have a routine which recursively steps all directories in Program Files (and the x86 directory).</p>
  
  <p>For each EXE it finds, the tool calls IsGuiApplication, passing the name of the EXE.</p>
  
  <p>From there, I create an Assembly object using LoadFrom. 
  I want to check whether this assembly is has a GUI output, but I'm unsure how to test this in C#.</p>
  
  <p>My current idea is to use GetStdHandle, but I'm not sure how to apply this to an assembly outside of the running application.</p>
  
  <p>My experience with reflection in C# is limited, so any help would be appreciated.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>using Microsoft.Win32;
  using System;
  using System.Collections.Generic;
  using System.IO;
  using System.Linq;
  using System.Reflection;
  using System.Runtime.InteropServices;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace BatchShortcutBuild
  {
      class Program
      {
          //I'm uncertain that I need to use this method
          [DllImport("kernel32.dll", SetLastError = true)]
          static extern IntPtr GetStdHandle(int nStdHandle);
  
          static void Main(string[] args) {
              BuildShortcuts();
              Console.ReadLine();
          }
  
          public static void BuildShortcuts() {
              String dirRoot = "C:\\Program Files\\";
              processRoot(dirRoot);
  
              dirRoot = "C:\\Program Files (x86)\\";
              processRoot(dirRoot);
  
              Console.WriteLine("Finished enumerating files");
              Console.ReadLine();
          }
  
  
          public static void processRoot(String path) {
              try {
                  foreach (String theDir in Directory.EnumerateDirectories(path)) {
                      processRoot(theDir);
                  }
  
                  foreach (String theFile in Directory.EnumerateFiles(path, "*.exe")) {
                      if (IsGuiApplication(theFile)) {
                          //I would generate a shortcut here
                      }
                  }
              } catch { }
          }
  
          public static bool IsGuiApplication(String filePath) {
              Console.WriteLine(filePath);
              Assembly a = Assembly.LoadFrom(filePath);
              //How to get the program type from the assembly?
              return false;
          }
  
      }
  }</code></pre>
  </div>
  </div>
  </p>