Restarting a Surface Pro 2

One Comment | Dec 09, 2013

Last Friday I encountered a problem resuming from sleep with my brand new Surface Pro 2. Of course this happened as I was getting everything ready to leave and catch a flight.

I had just put the Surface to sleep and realized I needed to get some information first. I tried to resume and nothing. After some basic troubleshooting I called Microsoft technical support.

Their technical support walked me through a few things including holding the power button down for longer then is normal to hard reset it. However, the magic tip was how to simulate the battery being removed.

To simulate the battery being removed and reinserted you hold down the Power and Volume Up buttons. And then release the Power button once you see the Surface logo. You go into a hardware setup screen. You exit from there and your Surface will restart as normal.

CryptoLicensing Evaluation

Add Comment | Nov 28, 2013

The software you write is valuable. Therefore, it should be protected. When you provide software for sale you need a mechanism to ensure it’s used within your purview. That mechanism usually involves licensing and copy-protection.

Enter CryptoLicensing

LogicNP handles the licensing and copy-protection using a military strength cryptographic technology. And it does so using a simple API that delivers all of the features you’d expect.

The webpage for CryptoLicensing lists all of the features. But, the following example demystifies the licensing process and proves how easy the software is to use.

Licensing Example

The documentation that comes with CryptoLicensing provides an example that is a good starting point.

The first thing you’ll do is create a licensing project using the CryptoLicensing Generator application. This allows use to create a key and any number of individual licenses for your application. The key is embedded in your application; and the licenses are normally provided to your end users. In the example, the license is embedded.

cldemo_keycodewindow

I took the example application a step further by encapsulating the licensing object in a special class. The implementation consists of a validation method and a property that provides a message that indicates the result of the validation.

The class implements IDisposable, because the CryptoLicense object does. There are areas that can be improved in my implementation. For example, you might want to keep the key and license strings as SecureString objects to keep them away from prying eyes.

public sealed class LicenseValidator : IDisposable
{
    readonly CryptoLicense licValidator;
    bool isDisposed = false;
    const string ValidationKey = "AMAAMAC…emkq==";

    public LicenseValidator()
    {
        licValidator = new CryptoLicense();
        licValidator.ValidationKey = ValidationKey;
    }

    public void Dispose()
    {
        licValidator.Dispose();
        isDisposed = true;
    }

    public string ResultMessage { get; private set; }

    public bool ValidateLicense(string licCode)
    {
        if (string.IsNullOrEmpty(licCode))
            throw new ArgumentNullException("licCode");
        if (isDisposed)
            throw new ObjectDisposedException("LicenseValidator");

        licValidator.LicenseCode = licCode;

        var status = licValidator.Status;
        ResultMessage = status.ToString();

        return (status == LicenseStatus.Valid);
    }
}

The LicenseValidator class is used at the start point of your application. I removed the reference to the startup window from App.xaml for my WPF application. And then I overloaded OnStartup in my App class.

protected override void OnStartup(StartupEventArgs e)
{
    base.OnStartup(e);

    using (var validator = new LicenseValidator())
    {
        string lic = "FgAAAAhH…vKldV9DE";

        if (validator.ValidateLicense(lic))
        {
            this.MainWindow = new MainWindow();
            this.MainWindow.Show();
        }
        else
        {
            MessageBox.Show("License validation failed ("
                + validator.ResultMessage + ")");
            this.Shutdown();
        }
    }
}

There is a glaring problem with this licensing example. It works, but the licensing key is hardcoded. And that’s not useful nor is it good practice.

The software provides three built-in ways of storing the license key. You can embed it as a resource in the assembly; although that is only slightly better than putting it in your code. You can also save it to a file or in the Registry.

The file and Registry options are the most useful, because they don’t tie the license code to your application. You then need a method of obtaining the license code from the user. CrytoLicensing has you covered there as well.

The EvaluationInfoDialog provides a mechanism to enter your license key in addition to verifying evaluation settings. The dialog works nicely enough to provide an easy way to enter a license. Unfortunately, it falls short in implementation.

cldemo_licentry

The problem is that the EvaluationInfoDialog inherits directly from System.Windows.Forms.Form. That means it’s a Windows Forms implementation. The ShowEvaluationInfoDialog method of the CryptoLicense object take this specific concrete class. Therefore, you’re stuck with a dependency on the Windows Forms technology if you want to use the built-in behavior and pattern. This is a poor design decision. It should have been implemented as an interface with one or two external concrete implementations.

Of course, there’s nothing stopping you from implementing your own dialog. Unfortunately, you’ll be on your own for the entire implementation. It’s a shame LogicNP didn’t implement this as well as the rest of their software. I  grudgingly added a reference to the System.Windows.Forms assembly for my WPF demo purposes.

The changes to my LicenseValidator class are minor. The signature of the ValidateLicense method changes. It no longer takes a license code as an argument. Instead, I attempt to load the license within that method. A helper method to show the dialog is also added.

public bool ValidateLicense()
{
    if (isDisposed)
        throw new ObjectDisposedException("LicenseValidator");

    if (!licValidator.Load())
    {
        if (!GetLicense())
        {
            ResultMessage = "License entry cancelled";
            return false;
        }
    }

    var status = licValidator.Status;
    ResultMessage = status.ToString();

    return (status == LicenseStatus.Valid);
}

private bool GetLicense()
{
    using (var dialog = new EvaluationInfoDialog(licValidator))
    {
        dialog.ProductName = "License Validator";
        dialog.PurchaseURL = "http://www.mycompany.com";

        return licValidator.ShowEvaluationInfoDialog(dialog);
    }
}

The changes to the App class are even simpler. I modify the method call, remove the license code variable, and I remove the message box, because the EvaluationInfoDialog shows what needs to be shown.

protected override void OnStartup(StartupEventArgs e)
{
    base.OnStartup(e);

    using (var validator = new LicenseValidator())
    {
        if (validator.ValidateLicense())
        {
            this.MainWindow = new MainWindow();
            this.MainWindow.Show();
        }
        else
        {
            this.Shutdown();
        }
    }
}

Beyond the Simple

That is only the beginning of the capabilities of CryptoLicensing. The demo illustrated a basic licensing situation. You will likely have more advanced needs.

The following are some of the licensing scenarios that you may need that the software supports:

Evaluation You define an evaluation license when you want your users to use your application for some limited duration. You can specify limits on days, execution count, total time used, et al.
Hardware-Locked This license option allows you to lock the license to a specific computer.
Activations You define a number of activations for the license, and a licensing service calculates a hardware-locked license for the computer that is being activated.
Concurrent This option is similar to the activated license. The difference is that the license is based on the number of activations at a given time. And a computer with an existing license can free it up for another to be activated.
With Features You can specify a license that enables specific features within your application, or you can define editions like Standard, Professional, and Enterprise.

The user interface within CryptoLicensing is setup with a series of tabs that have many options for defining your license. The first two define the main settings. And the second is related to .NET specific assemblies.

Profiles

Picking the correct settings for your project can be overwhelming. LogicNP provided a great feature called profiles to help with this. This feature allows you to create and save a series of settings based on your custom license.

You can create your own profiles or use one of the two that they provide out of the box – a normal license and a 30-day evaluation.

Licensing Service

Some of the features of CryptoLicensing require a licensing service. These features include concurrent licenses and dynamically hardware-locking licenses.

The provided licensing service is implemented as a Web service. It includes support for major eCommerce providers including PayPal, Plimus, et al.

The software installation comes with a complete Visual Studio solution that you compile and run after setting a few configuration options.

Usage Reporting

The licensing service comes with an added benefit. It can track how your application is used. This is similar in implementation to the Customer Experience Program you see in applications like Microsoft Office.

The part the user doesn’t see is a website you host. The website provides different views each of which focus on an aspect of the reported data. Usage reporting can be helpful in determining what features need your development resources.

Good and the Bad

The following are my general opinions about what sets CryptoLicensing apart and areas that could be improved.

Likes Dislikes
  • Features
  • Documentation
  • Application support
  • User interface
  • Windows Forms lock-ins

 

CryptoLicensing has a robust set of features that all work within the same interface. That means you’ll be able to add licensing features without requiring much rework of your existing code.

The documentation is excellent. The formatting can use some work, but you cannot complain about the content. LogicNP went above a simple documentation file and included several sample applications and instructional videos.

When I started using CryptoLicensing I thought it was going to be limited to your basic .NET application. It turns out that it supports many application types including Windows Phone, Mono, Mono Android, Windows Store, Office Addins, Sharepoint WebParts, et al.

I have the same complaints about the user interface as I do with Crypto Obfuscator. It’s convoluted and could use some attention. It’s easy for a developer to understand and use, but you may have a non-developer assigning and managing license codes when a licensing server isn’t involved.

My biggest complaint is the lock-in to Windows Forms for a couple of the helper windows. The UsageReportingConsentForm is derived from the Form class just as the EvaluationInfoDialog I already mentioned. There’s no reason you cannot implement your own, but there’s no good reason the implementation has been locked into a stagnant windowing technology either.

The Skinny

Licensing your software is a necessity in many cases in order to protect your intellectual property. But, it’s also a distraction from the core business problem you’re trying to solve. CryptoLicensing removes the distraction with a short learning curve and a robust set of features.

CryptoLicensing does everything I need for licensing. I plan on using it for my future projects that require licensing.

RegionManager missing from Namespace?

Add Comment | Oct 01, 2013

I struggled with an error in my XAML on a new project this weekend. The error is a design time error. That is, my project compiled and ran perfectly. But, the designer had the error:

The name ‘RegionManager’ does not exist in the namespace “http://www.codeplex.com/prism”.

This occurred in Visual Studio 2012 with the Prism 4.1 libraries that were especially compiled against .NET Framework 4.5. And that annoyingly had to be modified and resigned for the appropriate version of the Unity 3 library.

It turns out that the Zip file that the updated Prism libraries were distributed in was automatically blocked by Windows. When you decompress certain file types from a blocked Zip file the files will automatically be blocked as well. Fixing the problem was as simple as closing Visual Studio and unblocking each library using the following steps:

  1. Right click the library (DLL)
  2. Click Properties
  3. Click Unblock
  4. Click OK

You can also unblock the Zip and decompress the libraries again. However, in my case I had modified a library and it was easier to unblock the handful of files.

I hope this post will solve someone the hours it took me to solve this problem.

Crypto Obfuscator Evaluation

2 Comments | Sep 25, 2013
Obfuscation is the hiding of intended meaning. And within the context of programming it’s a necessary evil for different classes of programs. Programs written against the .NET Framework are compiled into intermediate code called Microsoft Intermediate Language (MSIL). MSIL preserves the structure and many of the details of your code. This makes decompiling trivial. Obfuscation isn’t something you think of as adding value to your program. It’s something you may be forced to do when you’re w

Removing Staged Windows 8 Apps

Add Comment | Sep 01, 2013

You may want to get rid of a built-in Windows 8 app such as News, Sports, et al. This is normally a straightforward operation – right click the app from the Start screen and choose Uninstall. In some cases your app can get stuck in a staged state. This can happen if you have pending updates for that application in the Windows Store.

A staged Windows 8 app will show {S-1-5-18 [Unknown user]: Staged} for the PackageUserInformation if you run get-appxpackage –allusers from within PowerShell.

Follow these steps to resolve the problem and remove the app completely:

  1. Install the update from the Windows Store
  2. Right-click the app from the Start screen and choose Uninstall

Access OLEDB Provider is not Registered

Add Comment | Aug 30, 2013

I ran into an error today involving connecting to a Microsoft Access database. I avoid Access like the plague. In this case, the program involves converting data in an Access database to a next generation system with a SQL Server database. Therefore, using Access is unavoidable.

I wired up my connections and got the appropriate connection strings using the old UDL trick. The connections tested successfully. However, the program would throw an InvalidOperationException when I tried to connect. The message within the exception is:

The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

This is one instance where an error has a lot of website hits. Maybe too many (the irony of me adding to that is not lost on me). At the end it wasn't clear to me why it's a problem. I do have the full Office suite installed. My OS and Office installation is 64-bit. And my program is set to Any CPU.

I got my answer from a Social MSDN response. Specifically, the part where he said that the version for 2007 is what made it work for him. And it worked for me too.

I installed the Access 2007 database engine and my program works. An extra bonus is that it hasn't appeared to break my Office 2013 installation.