Skip to content

Instantly share code, notes, and snippets.

@aont
Created November 6, 2010 11:41
Show Gist options
  • Save aont/665354 to your computer and use it in GitHub Desktop.
Save aont/665354 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
namespace NoDuplicatedStart
{
class Program
{
static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Process not specified...");
}
else
{
string ProcessFileName = args[0].ToLower();
string ProcessName = Regex.Match(ProcessFileName, @"([^\.\\]+)\.?\w*$").Groups[1].Value;
Console.WriteLine("Checking for duplication...");
foreach (Process p in Process.GetProcesses())
{
if (ProcessName == p.ProcessName)
{
Console.WriteLine("Already working...");
return;
}
}
StringBuilder arg_sb = new StringBuilder();
for (int i = 1; i < args.Length; ++i)
{
arg_sb.Append(args[i]);
arg_sb.Append(' ');
}
Console.WriteLine("Starting...");
Process process = new Process();
process.StartInfo = new ProcessStartInfo(args[0], arg_sb.ToString());
process.Start();
Console.WriteLine("Process started...");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment