下面以QQ为例:
#include <iostream>
#include <windows.h>
using namespace std;
#define RTN_ERROR 13
int main(void)
{
#define MY_BUFSIZE 132 // Arbitrary initial value.
// Dynamic allocation will be used.
HKEY hKey;
TCHAR szProductType[MY_BUFSIZE];
DWORD dwBufLen = MY_BUFSIZE;
LONG lRet;
// 下面是打开注册表, 只有打开后才能做其他操作
lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, // 要打开的根键
TEXT("SOFTWARE\\TENCENT\\QQ2009"), // 要打开的子子键
0, // 这个一定要为0
KEY_QUERY_VALUE, // 指定打开方式,此为读
&hKey); // 用来返回句柄
if(lRet != ERROR_SUCCESS) // 判断是否打开成功
return 1;
// 下面开始查询
lRet = RegQueryValueEx(hKey, // 打开注册表时返回的句柄
TEXT("Install"), //要查询的名称,qq安装目录记录在这个保存
NULL, // 一定为NULL或者0
NULL,
(LPBYTE)szProductType, // 我们要的东西放在这里
&dwBufLen);
if(lRet != ERROR_SUCCESS) // 判断是否查询成功
return 1;
RegCloseKey(hKey);
cout << (char*)szProductType;
strcat(szProductType,"\\Bin\\QQ.EXE");
WinExec(szProductType,SW_SHOW);
}