using System; using System.Diagnostics; using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms; class ButtonLauncher : Form { [DllImport("shell32.dll", CharSet = CharSet.Auto)] private static extern int ExtractIconEx( string lpszFile, int nIconIndex, IntPtr[] phiconLarge, IntPtr[] phiconSmall, int nIcons); [DllImport("user32.dll")] private static extern bool SetWindowPos( IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); private const uint SWP_NOZORDER = 0x0004; public ButtonLauncher() { this.FormBorderStyle = FormBorderStyle.None; this.TopMost = true; this.ShowInTaskbar = false; // ukrywa z taskbara this.StartPosition = FormStartPosition.Manual; // tymczasowy rozmiar, prawdziwy ustawimy w OnShown this.Size = new Size(100, 100); Button btn = new Button(); btn.Size = new Size(32, 32); btn.Location = new Point(2, 2); IntPtr[] largeIcon = new IntPtr[1]; ExtractIconEx("shell32.dll", 131, largeIcon, null, 1); if (largeIcon[0] != IntPtr.Zero) { Icon ico = Icon.FromHandle(largeIcon[0]); btn.Image = ico.ToBitmap(); btn.ImageAlign = ContentAlignment.MiddleCenter; } ToolTip tip = new ToolTip(); tip.SetToolTip(btn, "Stop MAN-Cats"); btn.Click += new EventHandler(this.ButtonClick); this.Controls.Add(btn); } protected override CreateParams CreateParams { get { const int WS_EX_TOOLWINDOW = 0x00000080; CreateParams cp = base.CreateParams; cp.ExStyle |= WS_EX_TOOLWINDOW; // ukrywa ikonę na pasku zadań return cp; } } protected override void OnShown(EventArgs e) { base.OnShown(e); int finalWidth = 36; int finalHeight = 36; // Pobranie rozdzielczości ekranu Rectangle screen = Screen.PrimaryScreen.WorkingArea; // Obliczenie pozycji 10 px od prawej, 5 px od góry int x = screen.Right - finalWidth - 10; int y = screen.Top + 5; // Ustawienie rozmiaru *i* pozycji przez WinAPI (działa poprawnie w XP) SetWindowPos( this.Handle, IntPtr.Zero, x, y, finalWidth, finalHeight, SWP_NOZORDER); } private void ButtonClick(object sender, EventArgs e) { string path = @"E:\MAN cats II\Runtime\mciikill.cmd"; string path2 = @"C:\MAN cats II\Runtime\mciikill.cmd"; if (System.IO.File.Exists(path2)) path = path2; if (!System.IO.File.Exists(path) && !System.IO.File.Exists(path2)) { MessageBox.Show("Doesnot exist: " + path); return; } ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "cmd.exe"; psi.Arguments = "/C \"" + path + "\""; // <--- WAŻNE: ścieżka w cudzysłowie psi.WindowStyle = ProcessWindowStyle.Hidden; psi.CreateNoWindow = true; try { Process.Start(psi); } catch (Exception ex) { MessageBox.Show("Script error: " + ex.Message); } } [STAThread] static void Main() { Application.EnableVisualStyles(); Application.Run(new ButtonLauncher()); } }