Pages

Saturday, January 29, 2011

How to export license keys that are already loaded in your system

Every now and then, there is a need to export license keys from a system.  I needed to get into the VAR layer to modify code in a Microsoft VPC, but as we all know, Contoso license keys don't come with the BUS/CUS/VAR access codes.  So I did what any developer would do:

  • Write a job to export the Contoso license key file
  • Import my company's partner license key file
    • DO NOT SYNC when it asks
  • Jump in the VAR layer using our layer access code to make my changes real quick
  • Import back the Contoso license key file I exported from my job and SYNC

Disclaimer (ripped from MS)
All code used below is meant for illustration purposes only and is not intended for use in production. The following disclaimer applies to all code used in this blog:

THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER. USE AND REDISTRIBUTION OF THIS CODE, WITH OR WITHOUT MODIFICATION, IS HEREBY PERMITTED.


Here is said job, enjoy!

static void OutputLicenseToText(Args _args)
{
    #define.licenseVersion(2)
    #define.KeywordLen(20)
    #define.keywordLicense('License')
    #define.keywordProperties('Properties')
    #define.keywordCodes('Codes')
    #define.keywordCodeLine('CodeLine')
    #define.keywordDate('Date')
    #define.keywordSerial('Serial')
    #define.keywordValue('Value')
    #define.blank('')
    #define.space1(' ')
    #define.space2('  ')
    #define.space3('   ')
    #define.spaceHash(' #')
    #define.OutputFilename(@'C:\OutputLicenseKeys.txt')

    #define.keywordInfo(1)
    #define.keywordWarning(2)

    SysConfig           sysConfig;
    SysLicenseCodeSort  sysLicenseCodeSort;
    container           fileOut;
    int                 i;
    System.IO.StreamWriter  sw;
    InteropPermission perm = new InteropPermission(InteropKind::ClrInterop);
    ;

    fileOut += "LicenseVersion "    + strfmt("%1", #licenseVersion);
    fileOut += #blank;
    fileOut += #keywordLicense      + #spaceHash + xSysConfig::find(ConfigType::LicenseName,0).Value;
    fileOut += #blank;
    fileOut += #space1  + #keywordProperties;
    fileOut += #space2  + "Name"            + #spaceHash    + xSysConfig::find(ConfigType::LicenseName,0).Value;
    fileOut += #space2  + #keywordSerial    + #spaceHash    + xSysConfig::find(ConfigType::SerialNo,0).Value;
    fileOut += #space2  + #keywordDate      + #spaceHash    + xSysConfig::find(ConfigType::LicenseName,1).Value;
    fileOut += #space1  + "EndProperties";
    fileOut += #blank;
    fileOut += #space1  + #keywordCodes;

    // Build CodeLines
    while select sysConfig
        where sysConfig.configType  == ConfigType::AccessCodes   &&
              sysConfig.value       != #blank
        join sysLicenseCodeSort
        order by SortIdx
        where sysLicenseCodeSort.Id == sysConfig.id
    {
        fileOut += #space2  + #keywordCodeLine  + #spaceHash    + int2str(sysConfig.id + 1);
        fileOut += #space3  + #keywordValue     + #spaceHash    + sysConfig.value;
        fileOut += #space2  + "EndCodeLine";
        fileOut += #blank;
    }

    fileOut += #blank;
    fileOut += #space2  + "EndCodes";
    fileOut += #space1  + "EndLicense";

    // Begin file output
    perm.assert();

    sw = new System.IO.StreamWriter(#OutputFilename);

    for (i=1; i<=conLen(fileOut); i++)
    {
        sw.WriteLine(conPeek(fileOut, i));
    }

    sw.Flush();
    sw.Close();
    sw.Dispose();

    CodeAccessPermission::revertAssert();

    info("License successfully output to " + #OutputFilename);
}

Installing Microsoft Dynamics AX 2009 Refresh 4 on Windows 7/Vista

Microsoft has released yet another wonderful VPC that showcases the entire stack of Microsoft products working with Dynamics AX 2009 (Can be found HERE with PartnerSource/CustomerSource).  Unfortunately...microsoft says:

This virtual machine is configured for Windows 2008 Hyper-V and can’t be used with VPC (or Windows 7 Virtualization)
You can get Refresh 3.5 to work as a VPC...but I'm going to show you a neat way to get Refresh 4 running as a dual bootable Dev environment.

This HowTo assumes you have downloaded Refresh 4 and extracted it and you have AX5-W8R2-01.vhd and AX5-W8R2-01_DB.vhd available.

Start by right clicking on computer and clicking "manage".

Go to Storage>Disk Management, then click the action menu at the top and click "Attach VHD".  Attach both VHDs.  You will need the AX5-W8R2-01_DB.vhd to be the F: drive, or once you mount it, you will need to copy over the files and file structure to the F: drive of your machine.  This is because this SQL instance looks for its database on the F: drive.

After you've added these, all you need to do is create a boot entry to boot the VHD's.  This can be done with the command line tool BCDboot.  If your Windows partition of the VHD is now on the E: drive for example, you just need to type from an elevated command prompt:
>bcdboot E:\windows
This will add a boot entry.  To see your work, just run "msconfig" and click the boot tab.  There you can set the default OS you'd like to boot, the wait time (I changed mine to 5 seconds), etc.

All that's left to do is restart the machine and make sure you select the Server 2008 R2 instance.  Expect the following:

  • First boot will be slow because all of the drivers are trying to sync to your new hardware
    • This means your desktop might not show up for several minutes
  • Page file issues initially (not sure why these occur, but I just ignore)
  • Some drivers you might have to manually download and install specific to your machine.  The only one I had to install was my graphics driver so that it would detect my two monitors.
This is nice because Refresh 4 requires a good amount of horsepower to run (recommended min of 4GB memory, dual CPU), and you can devote your entire machine to it.  Also dual monitors, etc feel nicer when it's not in a VPC window.

Happy DAX'ing!