1

Currently I'm implementing a licensing feature in our software using Babelfor.Net. Everything is working good except one thing - the licenses file must be placed in the same folder as the executing assembly and will then be loaded by the Babel.Licensing.XmlLicenseProvider which inherits the System.ComponentModel.LicenseProvider.

We are delivering a default, 30 day trial license along with the setup, so users can look around and eventually purchase a license. The default trial license must then be replaced by the new license - but a normal user does not have access to the Program Files directory, so either the user needs to start the application as an administrator or copy the file by hand - kind of hacky.

Is there a way to place the licenses file in %appdata% or %programdata%? Or maybe the installer could create a junction (symlink) which points to a licenses file in the %appdata% folder?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
lunatix
  • 817
  • 10
  • 25

3 Answers3

1

When running as non-admin on Vista/Win7/Win8 you can't write to the "Program files" folder (or any sub folder of it).

Have a look at Nir´s post :

The correct location to store user preference is (replace MyCompanyName and MyApplicationName with the correct names, obviously)

On disk:

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\MyCompanyName\\MyApplicationName"

Or in the registry under the key:

 HKEY_CURRENT_USER\Software\MyCompanyName\MyApplicationName

Those location are per-user and they work with non-admin user, several users using the same computer, fast user switching, terminal services and all the other ways people can interact with your software.

If you need a common location for all users then:

  1. It will only work when the user run as an administrator
  2. It will not work reliably on Vista
  3. You have to take care of everything yourself (like two users running the application on the same computer at the same time via fast user switching).

and the locations are:

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationCommonData) + "\\MyCompanyName\\MyApplicationName"

Or in the registry under the key:

 HKEY_LOCAL_MACHINE\Software\MyCompanyName\MyApplicationName
Community
  • 1
  • 1
SteMa
  • 421
  • 6
  • 13
  • As you can read in my post I am aware of this behavior and asking the question because of this behavior - it's a nice post though, but does not help to find a solution and does not answer my question.. – lunatix Aug 08 '14 at 10:42
1

You can tell to Babel where to find license file by code.

I use this code to find licenses in a subdirectory for a web site :

Babel.Licensing.XmlLicense.SearchDirectories = new string[] { Server.MapPath("~/Licenses") };

Something like :

Babel.Licensing.XmlLicense.SearchDirectories = new string[] { System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MyCompanyName", "MyApplicationName") };

(untested), should work.

Xav987
  • 1,182
  • 1
  • 15
  • 17
0

Your %appdata% or %programdata% folder idea could work. It is possible to find the current username from the OS, then (this would only work for Windows) you know the standard path for %appdata% or %programdata%

Only problem with that is sometime people will clear those folders out since they get filled with all sorts of junk.

MikeS159
  • 1,884
  • 3
  • 29
  • 54