fork download
  1. PS C:\users\bion\Desktop> type test.cs
  2. using System;
  3. using System.Runtime.InteropServices;
  4. using System.IO;
  5.  
  6. [Flags]
  7. public enum ExeType
  8. {
  9. None = 0,
  10. WinNT = 0x04000000,
  11. PE = ((int)'P') | ((int)'E' << 8),
  12. NE = ((int)'N') | ((int)'E' << 8),
  13. MZ = ((int)'M') | ((int)'Z' << 8),
  14. }
  15.  
  16. public static class Program
  17. {
  18. [DllImport("shell32.dll", CharSet=CharSet.Auto, EntryPoint="SHGetFileInfo")]
  19. public static extern ExeType GetExeType(string pszPath, uint dwFileAttributes = 0, IntPtr
  20. psfi = default(IntPtr), uint cbFileInfo = 0, uint uFlags = 0x2000);
  21.  
  22. public static void Main()
  23. {
  24. // Clearly a console application:
  25. Test("C:\\Windows\\System32\\cmd.exe");
  26. // Clearly a windowed application:
  27. Test("C:\\Windows\\System32\\Notepad.exe");
  28. }
  29.  
  30. private static void Test(string exe)
  31. {
  32. string shortName = Path.GetFileName(exe);
  33. int result = (int)GetExeType(exe);
  34. Console.WriteLine(shortName + " -> " + result.ToString("X8"));
  35. }
  36. }
  37. PS C:\users\bion\Desktop> csc test.cs
  38. Microsoft (R) Visual C# Compiler version 12.0.30723.0
  39. for C# 5
  40. Copyright (C) Microsoft Corporation. All rights reserved.
  41.  
  42. PS C:\users\bion\Desktop> .\test.exe
  43. cmd.exe -> 00004550
  44. Notepad.exe -> 06044550
  45. PS C:\users\bion\Desktop>
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty