Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Distributed Applications / May 2006

Tip: Looking for answers? Try searching our database.

Getting Calling Process name and information when using COM+

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cms0007@cs.unt.edu - 12 May 2006 15:39 GMT
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~";
            }
        }
    }
}
aelswify@gmail.com - 17 May 2006 07:53 GMT
There are 2 types of COM+ applications. Library which is inprocess, and
Server which is a stand alone process called dllhost.exe that is the
container (surrogate) for your COM+ objects or application.

Now, whatever you are doing above, you are querying process information
as if you are a library application whereas you are a server type COM+
application. So, the information you will be getting is about the
dllhost.exe rather than the client process itself.

No, so far I did not answer your question as I don't know the answer.
There is no standard way that you can get such information about the
calling process. Not that I know of.

Thanks,
Ashraf ElSwify
Software Architect.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.