Skip to content

Instantly share code, notes, and snippets.

@libraplanet
Created December 12, 2011 18:50
Show Gist options
  • Save libraplanet/1468551 to your computer and use it in GitHub Desktop.
Save libraplanet/1468551 to your computer and use it in GitHub Desktop.
rexe
@SETLOCAL
@SET PATH=C:\Windows\Microsoft.NET\Framework\v2.0.50727;%PATH%
@CALL cmd /k
@ENDLOCAL
@call .\clean.bat
@call .\compile.bat
@call .\run.bat
del rexe.exe
csc /out:rexe.exe Program.cs
using System;
using System.Diagnostics;
using System.Collections.Generic;
class Program
{
class NotProcessArgumentException : Exception {}
class PathMix
{
string path;
public PathMix(string path)
{
this.path = path;
}
public string OriginalPath
{
get
{
return path;
}
}
public string FullPath
{
get
{
return new Uri(path).LocalPath;
}
}
}
static void Main(string[] args)
{
Console.WriteLine("------------------------------------------");
Console.WriteLine(" application : rexe");
Console.WriteLine(" auther : takumi");
Console.WriteLine(" date : 11/12/13");
Console.WriteLine("------------------------------------------");
try
{
PathMix path;
List<Process> list = new List<Process>();
//args
{
Console.WriteLine("[args]");
if(args.Length > 0)
{
path = new PathMix(args[0]);
Console.WriteLine("path = " + path.FullPath + "(" + path.OriginalPath + ")");
}
else
{
throw new NotProcessArgumentException();
}
Console.WriteLine(" ");
}
{
Console.WriteLine("[process]");
//serch
{
foreach(Process p in Process.GetProcesses())
{
try
{
if(new PathMix(p.MainModule.FileName).FullPath == path.FullPath)
{
Console.WriteLine("fined id("+ p.Id +")");
list.Add(p);
}
}
catch
{
}
}
}
//kill
{
foreach(Process p in list)
{
int id = p.Id;
p.Kill();
Console.WriteLine("killed id("+ id +")");
}
}
//start
{
Process p = new Process();
p.StartInfo.FileName = path.FullPath;
p.Start();
Console.WriteLine("started id("+ p.Id +")");
}
}
}
catch(NotProcessArgumentException)
{
Console.WriteLine("No Argument...");
Console.WriteLine("");
Console.WriteLine("[help]");
Console.WriteLine("Usage: rexe [exepath]");
Console.WriteLine("");
Console.WriteLine("[exepath] : target execute file path.");
}
catch(Exception e)
{
Console.WriteLine("");
Console.WriteLine(e.ToString());
}
finally
{
}
}
}
rexe "C:\Program Files\Panasonic\WheelPad\WheelPad.exe"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment