Marketplace Client, Your Applications, and Registry Keys

Marketplace Client, Your Applications, and Registry Keys

  • Comments 2
  • Likes

marketplaceSmall The Windows Marketplace for Mobile is off to a great start since its release October 6th. One issue that has tripped up a few developers submitting their applications has been the use of internal registry keys used to determine the location of the application. Some clever developers have discovered that there is a list of installed applications stored in the registry under: HKEY_LOCAL_MACHINE\Software\Apps. Under the application name, you will find the directory in which the application has been installed. For example:

HKEY_LOCAL_MACHINE\Software\Apps\Company Application Name
InstallDir=”\Program Files\Application Name”

a similar list can be found here:

[HKEY_LOCAL_MACHINE\Security\AppInstall\Company Application Name]
InstallDir=”\Program Files\Application Name”

Since Windows Mobile does not support the concept of a current working directory, this has been one way to determine where the EXE is running from. A better approach, that is not dependant on these registry keys,  uses the following code (See Chistec’s blog post):

GetModuleFileName(GetModuleHandle(NULL), pszFullPath, MAX_PATH); 

For managed code (See Chistec’s blog post):

using System.Reflection;
private string GetApplicationExe()
{
  // Determine the full path to the application executable
  return Assembly.GetExecutingAssembly().GetName().CodeBase;
}

You can then parse out the application path from the returned file name.

So what is wrong with using these undocumented registry keys? When your application is installed by the Marketplace client, it creates these registry keys, but not with the names you would expect. Therefore, if your application is relying on any of these keys, if will fail to find them, because they will not exist.  This has tripped up a few developers because this issue does not surface unless you install the application after it has gone through the Marketplace ingestion process. (The processing of your application after it has passed certification testing.)

To summarize, if you need to get the directory in which it was your application was installed, use either the native or managed APIs above. Also, make sure you are not using either of these undocumented registry keys.

Thanks,

Mike

2 Comments
You must be logged in to comment. Sign in or Join Now
  • Would you believe that the #2 reason that people stumble upon my personal site is that they are looking for a way to find the current directory? Seems to be an extremely common and long running question.

  • private string GetApplicationExe()

    {

     // Determine the full path to the application executable

     return Assembly.GetExecutingAssembly().GetName().CodeBase;

    }

    I prefer this:

    private string GetApplicationExe()

    {

     // Determine the full path to the application executable

     return new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath;

    }

    Which parses out the URI .CodeBase returns into a local path.  But that's with the full framework, I've never used the Compact Framework so I dunno if it'll work there.  Uri is pretty basic stuff so I'm betting it does.