Click here to get back home

How to find program installation path (CodeBase unreliable)

 HomeNewsGroups | Search | About
 microsoft.public.smartphone.developer    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
How to find program installation path (CodeBase unreliable) abelikoff 08-24-2008
Get Chitika Premium
Posted by abelikoff on August 24, 2008, 6:21 pm
Please log in for more thread options


Hello - I'm trying to make my program reference a data file installed
along with the binary in the program directory (let's say \Program
Files\MYPROG\). Within a program, in order to find out the program
installation directory, I'm using the directory component of
Assembly.GetExecutingAssembly().GetName().CodeBase

Unfortunately, this only works when the program was started from that
directory. If the program was started from a shortcut on a Start Menu,
this property returns "\Windows\Start Menu\" which is obviously not
what I want.

So the question is, what is the right way (in .NET CF) to retrieve the
program installation directory (apart from hardcoding it).I suspect
that in the absence of a true API, one could make the setup script
create a registry key and place this directory in it, but I'm not sure
how to do it portably. I would very much appreciate any suggestions.

Regards,
-- Alexander

Posted by Peter Foot [MVP] on August 25, 2008, 12:34 am
Please log in for more thread options


P/Invoking GetModuleFileName allows you to get the full path of the launched
executable:-
http://mobileworld.appamundi.com/blogs/peterfoot/archive/2008/08/24/get-the-name-of-executing-exe.aspx

Peter

--
Peter Foot
Microsoft Device Application Development MVP
peterfoot.net | appamundi.com | inthehand.com
APPA Mundi Ltd - software solutions for a mobile world
In The Hand Ltd - .NET Components for Mobility

> Hello - I'm trying to make my program reference a data file installed
> along with the binary in the program directory (let's say \Program
> Files\MYPROG\). Within a program, in order to find out the program
> installation directory, I'm using the directory component of
> Assembly.GetExecutingAssembly().GetName().CodeBase
>
> Unfortunately, this only works when the program was started from that
> directory. If the program was started from a shortcut on a Start Menu,
> this property returns "\Windows\Start Menu\" which is obviously not
> what I want.
>
> So the question is, what is the right way (in .NET CF) to retrieve the
> program installation directory (apart from hardcoding it).I suspect
> that in the absence of a true API, one could make the setup script
> create a registry key and place this directory in it, but I'm not sure
> how to do it portably. I would very much appreciate any suggestions.
>
> Regards,
> -- Alexander


Posted by abelikoff on August 26, 2008, 2:22 am
Please log in for more thread options


Awesome! Thank you very much, Peter!

On Aug 25, 12:34=A0am, "Peter Foot [MVP]" <feedb...@nospam-
inthehand.com> wrote:
> P/Invoking GetModuleFileName allows you to get the full path of the launc=
hed
> executable:-http://mobileworld.appamundi.com/blogs/peterfoot/archive/2008=
/08/24/g...



Similar ThreadsPosted
Path for ONEXIT.C July 6, 2005, 12:58 am
Call Voice Path on WM 5 August 27, 2006, 11:40 am
Path to place the files for smartphones June 6, 2005, 10:13 pm
Getting the path of the image for SmartPhone Application WM 5.0. February 21, 2007, 8:54 am
About the ConnMgr's connections path selection logic June 28, 2006, 11:35 pm
How to understand the ConnMgrMapConRef API for specifying the fixed connection path June 29, 2006, 2:01 am
how to get default ringtone path on smartphone 2003 se? August 18, 2006, 9:31 pm
IPOutlookCollection Find() June 29, 2005, 3:58 am
I need an IME example for smarphone 2003, Where I can find it? July 26, 2005, 1:11 am
Couldn't find api ObexFindFileFirst, ObexFindFileNext in SDK December 8, 2006, 1:21 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap