Is there a way to get caller environment variables from Reflection?

S

SteveM

I am needing to get the environment variables (or at the very least
USERNAME and COMPUTERNAME) from a calling method in my (receiving)
library. So far I know how to get the method name, the class name and
even the file path of the calling method. I also know how to get the
line number where the call was made to my program from the other one,
but I also need to log the userName and the computerName running the
method that called mine. Is there a way to do that?

The reason I am doing this is that I am trying to convert an existing
Perl module that we have been using to C# (2.0).
The Perl code in the calling app is a simple one line statement: use
usageTracker();
I have something similar for the C# version: using (UsageTracker ut =
new UsageTracker()) {}
In the UsageTracker library, I use Reflection.MethodBase and
StackFrame to get the filepath of the calling program, the class name,
and the method name. I can also get the line number where the using
statement is being placed in the calling program. As I said I am just
lacking the userName of the user executing the code that calls mine,
and the machine name where the code is running. We use this
information to track usage of various tools we produce.

I hope there is a way to do this at runtime, if so please let me know
Thanks
-SteveM
 
S

SteveM

Sigh!
Nevermind It appears that my brain is a bit on the fritz, for some
reason I was thinking that the library that I am using
(UsageTracker()) would behave differently if it was on another machine
(such is in the case of a Perl module) What I didnt take into
consideration (its late friday afternoon what can I say :p) is that
the dll gets copied to the application that references it, and that by
simply using the GetEnvironementVariable() in my library code whoever
is calling my code will reveal their username and hostname via that
call.....
Just wasnt thinking clearly here.. sorry :-(
-SteveM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top