Getting Calling Process name and information when using COM+

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I have a DLL written in C# that does logging for many of our
processes. The calling process just passes messages and the DLL will
write the messages to a database with a unique log id for each instance
of a program that uses it so all messages passed by that program can be
identified by that single log id. As well, the logging DLL gets the ip
address, calling processname, and pid of the program calling it. The
calling program does not have to gather that info. The logging DLL
obtains it. I notice though that when the logging DLL is called by a
process running under COM+ the process name written to the database is
DLLHOST. I understand why that is but I want to know how to get the
name of the real calling process, not DLLHOST. So for instance if
Executablea.exe calls LinkLibrarya.dll which is installed in COM+ and
LinkLibrarya.Dll uses the logging dll, I want to know how the logging
dll can obtain the calling processes Executablea.exe and/or
linklibrarya.dll. I do not want the calling processes to have to
obtain the information and pass it in the call to the logging DLL.

Here is code in the logging dll I use to get the calling process names:


using System;
using System.Diagnostics;
using System.Reflection;
using System.Net;

namespace testprocessname
{
public class ProcNames
{
public ProcNames()
{
m_strCallingProcess =
Assembly.GetCallingAssembly().GetName().Name.ToString();
}

public string GetInfo()
{
return m_strProgramName + "^" + GetExeAssembly() + "^" +
GetCallAssembly() + "^" + GetEnterAssembly();
}

public static string GetStaticInfo()
{
return Process.GetCurrentProcess().ProcessName.ToString() + "^" +
GetStaticExeAssembly() + "^" + GetStaticCallAssembly() + "^" +
GetStaticEnterAssembly();
}

private string m_strProgramName =
Process.GetCurrentProcess().ProcessName.ToString();
private string m_strCallingProcess = "";



private string GetEnterAssembly()
{
try
{
return Assembly.GetEntryAssembly().GetName().Name.ToString();
}
catch
{
return Process.GetCurrentProcess().ProcessName.ToString() +
"~error~";
}
}

private string GetExeAssembly()
{
try
{
return Assembly.GetExecutingAssembly().GetName().Name.ToString();
}
catch
{
return Process.GetCurrentProcess().ProcessName.ToString() +
"~error~";
}
}

private string GetCallAssembly()
{
try
{
return Assembly.GetCallingAssembly().GetName().Name.ToString();
}
catch
{
return Process.GetCurrentProcess().ProcessName.ToString() +
"~error~";
}
}

private static string GetStaticEnterAssembly()
{
try
{
return Assembly.GetEntryAssembly().GetName().Name.ToString();
}
catch
{
return Process.GetCurrentProcess().ProcessName.ToString() +
"~error~";
}
}

private static string GetStaticExeAssembly()
{
try
{
return Assembly.GetExecutingAssembly().GetName().Name.ToString();
}
catch
{
return Process.GetCurrentProcess().ProcessName.ToString() +
"~error~";
}
}

private static string GetStaticCallAssembly()
{
try
{
return Assembly.GetCallingAssembly().GetName().Name.ToString();
}
catch
{
return Process.GetCurrentProcess().ProcessName.ToString() +
"~error~";
}
}
}
}

.



Relevant Pages

  • Re: logging pass from exe to dll
    ... Been doing logging to text file via simple commands in a bas file ... when control passes from the exe to the dll (via an Init method on the ...
    (microsoft.public.vb.general.discussion)
  • Re: C# 3.0 runtime macros and log4net
    ... generate the logging, but if the dll is not loaded, nothing happens? ... private Assembly asm; ... public void DebugFormat(string fmt, params objectargs) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Getting handle to calling dll/exe
    ... calling process has own methods to handle errors, messages, etc: ... gcomm.dll is the part that uses fyba, so I would like to be able to put ... Inside the DLL, I look for an export with a given name ... exported by executables. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: ASP.NET DLL Hell?
    ... then logging out, then loggin in as another person. ... When he logs out and another logs in, ... Instead the old dll runs. ... >> I replaced application DLL in Bin directory with a new version to support ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Logging from a .dll
    ... As long as the EXE can create an object that derives from that interface, and can pass that object to the classes defined in the DLL, then the classes in the DLL can call the object to perform the logging. ... But my logging method is in the .exe ...
    (microsoft.public.dotnet.general)