Home > Software Deployment > Installscript to Transform GUID into ‘Compressed GUID’

Installscript to Transform GUID into ‘Compressed GUID’

I recently undertook a task that required me to manipulate the registry directly to overcome limitations of MSI. One requirement of this task was to transform a product code’s GUID into a ‘compressed GUID’ as stored in the registry.  (maybe a more apt name would be obfuscated GUID, because that’s what it really is!)

Installshield has a whitepaper outlining the logic for the transform used in the code I’m providing.

The compressed GUID can be found throughout the registry.  A few places that come to mind are:

  • HKEY_LOCAL_MACHINE\Software\Classes\Installer\Products\
  • HKEY_CLASSES_ROOT\Installer\Products\

Place the following at the header of the .rul Installscript file.

prototype string CompressedGUID(STRING);
prototype string ReverseString(STRING);

Place the following 2 functions anywhere in the .rul Installscript file.

// Function:  CompressedGUID
//  Purpose:  Converts original GUID to Compressed GUID. (as stored in registry)
// param name=szOriginal GUID to be compressed.
// returns compressed guid.
function string CompressedGUID(szOriginal)
	STRING szCompressed;
	STRING szSub;
	STRING szReturn;

	szCompressed = szOriginal;
	StrSub(szSub, szCompressed,0,8);
	szReturn = ReverseString(szSub);

	StrSub(szSub, szCompressed,8,4);
	szReturn = szReturn + ReverseString(szSub);

	StrSub(szSub, szCompressed,12,4);
	szReturn = szReturn + ReverseString(szSub);

	StrSub(szSub, szCompressed,16,2);
	szReturn = szReturn + ReverseString(szSub);

	StrSub(szSub, szCompressed,18,2);
	szReturn = szReturn + ReverseString(szSub);

	StrSub(szSub, szCompressed,20,2);
	szReturn = szReturn + ReverseString(szSub);

	StrSub(szSub, szCompressed,22,2);
	szReturn = szReturn + ReverseString(szSub);

	StrSub(szSub, szCompressed,24,2);
	szReturn = szReturn + ReverseString(szSub);

	StrSub(szSub, szCompressed,26,2);
	szReturn = szReturn + ReverseString(szSub);

	StrSub(szSub, szCompressed,28,2);
	szReturn = szReturn + ReverseString(szSub);

	StrSub(szSub, szCompressed,30,2);
	szReturn = szReturn + ReverseString(szSub);
return szReturn;

// Function:  ReverseString
//  Purpose:  Reverse string.
// param name="szOriginal>string to be reversed
// returns the reversed string.
function STRING ReverseString(szOriginal)
	STRING szReversed, szValue;
	INT nvIndex;
	szReversed = "";
	for nvIndex = 0 to StrLength(szOriginal) - 1
	StrSub(szValue, szOriginal, nvIndex, 1);
	szReversed = szValue + szReversed;
	return szReversed;

Now it’s possible to use the following anywhere in the code. The szReturnValue variable contains the ‘compressed GUID’

szReturnValue = CompressedGUID("{EAFD321F-7441-49F7-845F-162AFE9A9E89}");

If you prefer vbscript (I hope you don’t for msi tasks), I found a quick algorithm here
If you prefer C#, here’s your cure. Also, this link is from Scott Hanselman minutes. Great podcast!

  1. May 2, 2011 at 4:18 pm

    Nice. What’s the reason for obfuscating the GUID?

  2. Vic Yuschuk
    December 18, 2012 at 9:05 pm

    I was just about to write something like this. Thanks for posting!

  1. July 27, 2011 at 8:11 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: