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 / New Users / February 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SteveM - 23 Feb 2007 21:41 GMT
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
SteveM - 23 Feb 2007 22:41 GMT
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

> I am needing to get the environment variables (or at the very least
> USERNAME and COMPUTERNAME) from a calling method in my (receiving)
[quoted text clipped - 21 lines]
> Thanks
> -SteveM

Rate this thread:







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.