-
-
Save RickDB/aeff5cddc70bb181811b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Runtime.InteropServices; | |
namespace SendWindowCMD | |
{ | |
class Program | |
{ | |
[DllImport("user32.dll", CharSet = CharSet.Auto)] | |
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam); | |
const uint WmClose = 0x0010; | |
static void Main(string[] args) | |
{ | |
if (args.Any()) | |
{ | |
if (args[0].Equals("CloseMediaportal")) | |
{ | |
CloseMediaportalWindow(); | |
} | |
} | |
} | |
static void CloseMediaportalWindow() | |
{ | |
IntPtr hWnd = IntPtr.Zero; | |
foreach (Process pList in Process.GetProcesses()) | |
{ | |
if (pList.MainWindowTitle.ToLower().StartsWith("mediaportal")) | |
{ | |
hWnd = pList.MainWindowHandle; | |
if (hWnd == IntPtr.Zero) | |
{ | |
Console.WriteLine("Window not found"); | |
} | |
else | |
{ | |
Console.WriteLine("Closing Mediaportal window"); | |
SendMessage(hWnd, WmClose, IntPtr.Zero, IntPtr.Zero); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment