Hi I'm having some headaches trying to find how to get the process of a parent application that starts my C# console app.
I've been trying a lot of things all day and come up short.
The most likely candidate was this, except it does not return what I expect and tackes abot 1000 ms to return.
static void Main(string[] args)
{
var pcs = Process.GetCurrentProcess();
Console.WriteLine(pcs);
Console.ReadLine();
}
Also tried
static void Main(string[] args)
{
var pc = Process.GetProcessById(0);//.ProcessName);
Console.WriteLine(pc);
Console.ReadLine();
}
And a number of other attempts.
Im after the string path, and or PID of the process that starts my app.
Anyone know how to achieve this?
Edit:
Heres how I've done it in C++
void pname(void)
{
HMODULE module = GetModuleHandle(NULL);
if(!module)
{
return;
}
TCHAR name[MAX_PATH] = { };
if(GetModuleFileName(module, name, MAX_PATH) == 0)
{
return;
}
MessageBox(NULL,name,_T("name"),0);
}