Skip to content

Instantly share code, notes, and snippets.

@rzhw
Created December 12, 2013 10:29
Show Gist options
  • Save rzhw/7114c0da8f707d67d09f to your computer and use it in GitHub Desktop.
Save rzhw/7114c0da8f707d67d09f to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.IO.Pipes;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SHUTDOWNEVERYTHING
{
class Program
{
private static readonly byte[] validateBytes = new[] { 'S', 'Q', 'U', 'I', 'R', 'R', 'E', 'L' }.Select(x => (byte)x).ToArray();
private static readonly byte[] exitMessage = new[] { 'E', 'X', 'I', 'T' }.Select(x => (byte)x).ToArray();
static void Main(string[] args)
{
// note I did a s/Shimmer/Squirrel on the sample
// if you kept the package name as ShimmerDesktopDemo change it here
var pipeClient = new NamedPipeClientStream(".", "SquirrelPipe SquirrelDesktopDemo", PipeDirection.InOut, PipeOptions.None);
bool connected = false;
try
{
pipeClient.Connect(1000);
connected = true;
}
catch (TimeoutException) { }
if (connected)
{
var buffer = new byte[validateBytes.Length];
pipeClient.Read(buffer, 0, validateBytes.Length);
if (buffer.SequenceEqual(validateBytes))
{
pipeClient.Write(exitMessage, 0, exitMessage.Length);
Console.WriteLine("Attempted to request running instance to exit");
}
else
{
Console.WriteLine("Connected to a named pipe but didn't respond or wasn't Squirrel");
}
}
else
{
Console.WriteLine("No running instances found to request exit");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment