Not really an answer, though I'd be keen to understand the issue better. Here's the code I've just whipped up to display the things I mention.
Code:
#include <windows.h>
#include <stdio.h>
byte* GetRegistryKeyValue(const char* RegKey, const char* pPIDName)
{
HKEY Registry;
long ReturnStatus;
DWORD regType = 0;
DWORD regSize = 0;
byte* pPID = 0;
ReturnStatus = RegOpenKeyEx( HKEY_LOCAL_MACHINE, RegKey, 0, KEY_QUERY_VALUE, &Registry );
if ( ReturnStatus == ERROR_SUCCESS )
{
ReturnStatus = RegQueryValueEx(Registry, pPIDName, 0, ®Type, 0, ®Size);
pPID = new byte[ regSize ];
ReturnStatus = RegQueryValueEx( Registry, pPIDName, 0, ®Type, pPID, ®Size );
RegCloseKey( Registry );
if ( pPID[regSize] > 127 || pPID[regSize] < 32 )
{
pPID[regSize] = '\0';
}
if ( regSize > 1 )
{
printf("Size > 1 (%d)\n", regSize);
return pPID;
}
else
{
printf("Size not > 1 (%d)\n", regSize);
return NULL;
}
}
else
{
RegCloseKey( Registry );
return NULL;
}
}
int main()
{
BYTE *resultData;
printf("-\n");
resultData = GetRegistryKeyValue("SOFTWARE\\MICROSOFT\\Windows NT\\CurrentVersion", "ProductName");
printf("ProductName: %s\n",resultData);
delete resultData;
printf("-\n");
resultData = GetRegistryKeyValue("SOFTWARE\\MICROSOFT\\Windows NT\\CurrentVersion", "ProductId");
delete resultData;
printf("-\n");
resultData = GetRegistryKeyValue("SOFTWARE\\MICROSOFT\\Windows NT\\CurrentVersion", "DigitalProductId");
delete resultData;
printf("-\n");
resultData = GetRegistryKeyValue("SOFTWARE\\MICROSOFT\\Windows NT\\CurrentVersion", "RegisteredOwner");
printf("RegisteredOwner: %s\n",resultData);
delete resultData;
printf("-\n");
resultData = GetRegistryKeyValue("SOFTWARE\\MICROSOFT\\Windows NT\\CurrentVersion", "CSDVersion");
printf("ServicePack: %s\n",resultData);
delete resultData;
return 0;
}
</stdio.h></windows.h>
Result:
-
Size > 1 (23)
ProductName: Windows 7 Home Premium
-
Size not > 1 (0)
-
Size not > 1 (0)
-
Size > 1 (10)
RegisteredOwner: Microsoft
-
Size not > 1 (0)
ServicePack: (null)
Process returned 0 (0x0) execution time : 0.103 s
Press any key to continue.
Keys as displayed by RegEdit:
ProductName = "Windows 7 Home Premium"
ProductId = "00359-OEM-8992687-00006"
DigitalProductId = (164 bytes)
RegisteredOwner = "enhzflep"
CSDVersion = "1"
Clearly, all but one of these values are being incorrectly reported on my machine.
Also, we can see that attempts to retrieve ProductId and DigitalProductId fail, since RegQueryValueEx is returning the number of bytes read as zero.
This same code behaves differently under XP x86 and Win7 x64.
Anybody else have any suggestions?
I also have the decode function to turn the (encrypted)DigitalProductId key back into the (decrypted, plain-text)product key used when installing the OS if anybody wants it.