Skip to content

Instantly share code, notes, and snippets.

@RickDB
Created January 2, 2016 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RickDB/aeff5cddc70bb181811b to your computer and use it in GitHub Desktop.
Save RickDB/aeff5cddc70bb181811b to your computer and use it in GitHub Desktop.
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