Advertisement
Manu404

ExLauncherInvisible2

Jun 6th, 2011
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Runtime.InteropServices;
  6. using System.Diagnostics;
  7. using System.Security;
  8. using System.Threading;
  9. using System.Collections;
  10.  
  11. namespace PuttyShadow
  12. {
  13.     class Program
  14.     {
  15.         static void Main(string[] args)
  16.         {
  17.             // Configure un nom unique au launcher puis le cache
  18.             Console.Title = Guid.NewGuid().ToString();
  19.             Windows w = new Windows();
  20.             foreach (Window wItem in w)
  21.             {
  22.                 if (wItem.Title == Console.Title)
  23.                     wItem.Visible = false;
  24.             }
  25.  
  26.             // Création du process a lancer
  27.             Process p = new Process();
  28.             p.StartInfo.FileName = @"C:\SVN\HomeServer\Visual Studio Projects\PminiRelayShadow\PminiRelayShadow\bin\Debug\miniRelay.exe";
  29.             p.Start();
  30.             Thread.Sleep(100);
  31.  
  32.             // On retrouve la fenêtre et on la cache ^^
  33.             w = new Windows();
  34.             foreach (Window wItem in w)
  35.             {
  36.                 if (wItem.Title.Contains("miniRelay"))
  37.                     wItem.Visible = false;
  38.             }
  39.            
  40.             p.WaitForExit();
  41.         }
  42.     }
  43.     public class Window
  44.     {
  45.  
  46.         [DllImport("user32.dll")]
  47.         private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
  48.         [DllImport("user32.dll")]
  49.         private static extern bool SetForegroundWindow(IntPtr hWnd);
  50.         [DllImport("user32.dll")]
  51.         private static extern bool IsIconic(IntPtr hWnd);
  52.         [DllImport("user32.dll")]
  53.         private static extern bool IsZoomed(IntPtr hWnd);
  54.         [DllImport("user32.dll")]
  55.         private static extern IntPtr GetForegroundWindow();
  56.         [DllImport("user32.dll")]
  57.         private static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
  58.         [DllImport("user32.dll")]
  59.         private static extern IntPtr AttachThreadInput(IntPtr idAttach, IntPtr idAttachTo, int fAttach);
  60.  
  61.  
  62.         private const int SW_HIDE = 0;
  63.         private const int SW_SHOWNORMAL = 1;
  64.         private const int SW_SHOWMINIMIZED = 2;
  65.         private const int SW_SHOWMAXIMIZED = 3;
  66.         private const int SW_SHOWNOACTIVATE = 4;
  67.         private const int SW_RESTORE = 9;
  68.         private const int SW_SHOWDEFAULT = 10;
  69.  
  70.         private IntPtr m_hWnd;
  71.         private string m_Title;
  72.         private bool m_Visible = true;
  73.         private string m_Process;
  74.         private bool m_WasMax = false;
  75.  
  76.         public IntPtr hWnd
  77.         {
  78.             get { return m_hWnd; }
  79.         }
  80.         public string Title
  81.         {
  82.             get { return m_Title; }
  83.         }
  84.         public string Process
  85.         {
  86.             get { return m_Process; }
  87.         }
  88.  
  89.         public bool Visible
  90.         {
  91.             get { return m_Visible; }
  92.             set
  93.             {
  94.                 if (value == true)
  95.                 {
  96.                     if (m_WasMax)
  97.                     {
  98.                         if (ShowWindowAsync(m_hWnd, SW_SHOWMAXIMIZED))
  99.                             m_Visible = true;
  100.                     }
  101.                     else
  102.                     {
  103.                         if (ShowWindowAsync(m_hWnd, SW_SHOWNORMAL))
  104.                             m_Visible = true;
  105.                     }
  106.                 }
  107.                 if (value == false)
  108.                 {
  109.                     m_WasMax = IsZoomed(m_hWnd);
  110.                     if (ShowWindowAsync(m_hWnd, SW_HIDE))
  111.                         m_Visible = false;
  112.                 }
  113.             }
  114.         }
  115.  
  116.         public Window(string Title, IntPtr hWnd, string Process)
  117.         {
  118.             m_Title = Title;
  119.             m_hWnd = hWnd;
  120.             m_Process = Process;
  121.         }
  122.  
  123.         public override string ToString()
  124.         {
  125.             if (m_Title.Length > 0)
  126.                 return m_Title;
  127.             else
  128.                 return m_Process;
  129.         }
  130.     }
  131.  
  132.     public class Windows : IEnumerable, IEnumerator
  133.     {
  134.         [DllImport("user32.dll")]
  135.         private static extern int GetWindowText(int hWnd, StringBuilder title, int size);
  136.         [DllImport("user32.dll")]
  137.         private static extern int GetWindowModuleFileName(int hWnd, StringBuilder title, int size);
  138.         [DllImport("user32.dll")]
  139.         private static extern int EnumWindows(EnumWindowsProc ewp, int lParam);
  140.         [DllImport("user32.dll")]
  141.         private static extern bool IsWindowVisible(int hWnd);
  142.  
  143.         public delegate bool EnumWindowsProc(int hWnd, int lParam);
  144.         private int m_Position = -1;
  145.         ArrayList wndArray = new ArrayList();
  146.  
  147.         private bool m_invisible = false;
  148.         private bool m_notitle = false;
  149.  
  150.         public Windows(bool Invisible, bool Untitled)
  151.         {
  152.             m_invisible = Invisible;
  153.             m_notitle = Untitled;
  154.             EnumWindowsProc ewp = new EnumWindowsProc(EvalWindow);
  155.             EnumWindows(ewp, 0);
  156.         }
  157.  
  158.         public Windows()
  159.         {
  160.             EnumWindowsProc ewp = new EnumWindowsProc(EvalWindow);
  161.             EnumWindows(ewp, 0);
  162.         }
  163.  
  164.         private bool EvalWindow(int hWnd, int lParam)
  165.         {
  166.             if (m_invisible == false && !IsWindowVisible(hWnd))
  167.                 return (true);
  168.  
  169.             StringBuilder title = new StringBuilder(256);
  170.             StringBuilder module = new StringBuilder(256);
  171.  
  172.             GetWindowModuleFileName(hWnd, module, 256);
  173.             GetWindowText(hWnd, title, 256);
  174.  
  175.             if (m_notitle == false && title.Length == 0)
  176.                 return (true);
  177.  
  178.             wndArray.Add(new Window(title.ToString(), (IntPtr)hWnd,
  179.                                     module.ToString()));
  180.  
  181.             return (true);
  182.         }
  183.  
  184.         public IEnumerator GetEnumerator()
  185.         {
  186.             return (IEnumerator)this;
  187.         }
  188.  
  189.         public bool MoveNext()
  190.         {
  191.             m_Position++;
  192.             if (m_Position < wndArray.Count)
  193.             {
  194.                 return true;
  195.             }
  196.             else
  197.             {
  198.                 return false;
  199.             }
  200.         }
  201.         public void Reset()
  202.         {
  203.             m_Position = -1;
  204.         }
  205.         public object Current
  206.         {
  207.             get
  208.             {
  209.                 return wndArray[m_Position];
  210.             }
  211.         }
  212.     }
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement