get valuetype of registry

Is there a way to retrieve the type of the registry value? I found this

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/reggetvalue.asp

but the requirements are as follows

Requires Windows Vista or Windows XP Professional x64 Edition.

I need a solution that will work on windows xp, 98 etc.  I have searched and have not been able to find anything... It must be doable since regedit shows the datatype? If there is a component out there that can do the job great. Or a function or something? I just want to see which datatype it is i.e

REG_BINARY       
REG_DWORD       
REG_DWORD_LITTLE_ENDIAN       
REG_DWORD_BIG_ENDIAN       
REG_EXPAND_SZ       
REG_LINK       
REG_MULTI_SZ       
REG_NONE       
REG_QWORD       
REG_QWORD_LITTLE_ENDIAN       
REG_SZ

Note: I will be using or calling the final solution from  C#
dotnet22Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

razvaRCommented:
Hi dotnet22,

You can use RegQueryValueEx to get the registry key type, here is a function that will do that:

DWORD __fastcall GetKeyType (HKEY hRootKey, AnsiString KeyPath,AnsiString ValueName)
{
  HKEY hkResult;
  DWORD kType;
  if (RegOpenKeyEx (hRootKey,KeyPath.c_str(),0,KEY_QUERY_VALUE,&hkResult)!=ERROR_SUCCESS )
   return -1;
 if ( RegQueryValueEx (hkResult,ValueName.c_str(),NULL, &kType,NULL,NULL)!=ERROR_SUCCESS)
    kType=-1;
  RegCloseKey(hkResult);
  return kType;
}

Here is an example on how to use the above function:

void __fastcall TForm1::ButShowMeKeyTypeClick(TObject *Sender)
{
 DWORD kType=GetKeyType(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Web Service Providers","PPCheckInterval");
 AnsiString descr;
 switch (kType)
  {
    case REG_NONE:
         descr="REG_NONE";
         break;
    case REG_SZ :
         descr= "REG_SZ";
         break;
    case REG_EXPAND_SZ:
        descr = "REG_EXPAND_SZ";
        break;
    case REG_BINARY:
        descr= "REG_BINARY";
        break;
    case REG_DWORD_LITTLE_ENDIAN:
         descr="REG_DWORD_LITTLE_ENDIAN (same as REG_DWORD)";
         break;
    case REG_DWORD_BIG_ENDIAN :
         descr="REG_DWORD_BIG_ENDIAN";
         break;
    case  REG_LINK:
        descr="REG_LINK";
        break;
    case  REG_MULTI_SZ:
       descr="REG_MULTI_SZ";
       break;
    case  REG_RESOURCE_LIST:
       descr="REG_RESOURCE_LIST";
       break;
    case  REG_FULL_RESOURCE_DESCRIPTOR:
       descr="REG_FULL_RESOURCE_DESCRIPTOR";
       break;
    case  REG_RESOURCE_REQUIREMENTS_LIST:
       descr="REG_RESOURCE_REQUIREMENTS_LIST";
       break;
    case  REG_QWORD:
       descr= "REG_QWORD_LITTLE_ENDIAN";
       break;
   default:
      descr="unknown or not found";
  }

  ShowMessage(descr);
}

It will work on Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.

More info about windows registry you can find on msdn: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/registry.asp
Hope it helps, good luck!

_
Raz

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.