Created
November 6, 2010 11:41
-
-
Save aont/665354 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.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