Locations of visitors to this page
    Sprouting Synapses       Minimize  

             
            Minimize  
Author: SkySigal Created: 8/28/2008 12:11 AM
Posts about getting information about the Environment your application is running in (eg: UserName, AppDir, Data Dir, etc.)

By SkySigal on 9/29/2008 2:23 PM

The CurrentWorkingDirectory is...a tar pit for people looking to emulate VB6's AppDir (or whatever it was called).
It's true that Process sets it to the app's startup dir when starting an application...but its absolutely the last thing to rely on as a quick AppDir property.

Why? Because other things change it -- such as FileDialog:

<<<
Anyhow, to cut a long story short, the FileDialog changes the current working directory to the last selected directory (unless a property is set: RestoreDirectory). This causes the assembly loader to look in the incorrect directory.
>>>

His solution was to instead rely on AppDomain.CurrentDomain.SetupInformation.ApplicationBase which solves some of the problems

Note that it works for PC, ASP.NET, but not CF, as demonstrated here: http://demos.xact-solutions.com/Investigations/ASP.NET/AppDir/Default.aspx

Getting a cross platform solution to entry assembly and startup path is more complicated really...requires precompiler directives, P/Invoke on CF, etc.

 

Link:

powered by metaPost

By SkySigal on 9/27/2008 12:01 AM

I'm used to this approach:

System.Environment.Version

which gives

2.0.50727.3053

but I've just bumped into this (again...but I had totally forgotten about it):

string s = 
System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion();

which gives:

"v2.0.50727"

Still like the the Environment property better, but the RuntimeEnvironment has some other juicy properties and methods that that may come in handy some day. For example:

System.Runtime.InteropServices.RuntimeEnvironment.SystemConfigurationFile;
gave me:
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config
and
System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();

gave me:

c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\

Can't see how this could be useful to me any time soon...but park just in case.

Links:

powered by metaPost

By SkySigal on 8/27/2008 11:48 PM

 

A complete list of Environment Variables (eg: %ALLUSERSPROFILE%, etc) that are sometimes needed...

Read More »


             
Copyright 2007 by Sky Sigal