Files
shadowsocks-windows/shadowsocks-csharp/Util/ProcessManagement/ThreadUtil.cs
T
Noisyfox a1eef6eac1 Multiple instances of ss_privoxy (#665)
* Use job object to manage polipo service's external processes.

Signed-off-by: noisyfox <timemanager.rick@gmail.com>

* Only kill those ss_privoxy.exe created by this ss instance.

Signed-off-by: noisyfox <timemanager.rick@gmail.com>

* Update README

Signed-off-by: noisyfox <timemanager.rick@gmail.com>
2016-08-18 19:31:01 +08:00

32 lines
932 B
C#

using System.Diagnostics;
using System.Management;
using System.Text;
namespace Shadowsocks.Util.ProcessManagement
{
static class ThreadUtil
{
/*
* See:
* http://stackoverflow.com/questions/2633628/can-i-get-command-line-arguments-of-other-processes-from-net-c
*/
public static string GetCommandLine(this Process process)
{
var commandLine = new StringBuilder(process.MainModule.FileName);
commandLine.Append(" ");
using (var searcher = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + process.Id))
{
foreach (var @object in searcher.Get())
{
commandLine.Append(@object["CommandLine"]);
commandLine.Append(" ");
}
}
return commandLine.ToString();
}
}
}