1.主要是读取注册表中HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs的值,至于怎么读取注册表。
C++中:
HKEY hKey;
RegOpenKey(HKEY_LOCAL_MACHINE,"HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs",&hKey);
DWORD dwType;//返回类型
char buffer[20];//数据缓存
DWORD dwValue;//数据长度
RegQueryValueEx(hKey,NULL,0,&dwType,(LPBYTE)buffer,&dwValue);
buffer[dwValue]=0;
CString str;
str.Format("%s",buffer);
MessageBox(str);
2.下面是别人写的
********************************************************************
// purpose : to master the arith of bianli
#include <stdio.h>
#include <time.h>
#include <windows.h>
HKEY hKey[] = {HKEY_CLASSES_ROOT,
HKEY_CURRENT_USER,
HKEY_LOCAL_MACHINE,
HKEY_USERS,
HKEY_CURRENT_CONFIG};
char *sKey[] = { "HEKY_CLASSES_ROOT ",
"HEKY_CURRENT_USER ",
"HEKY_LOCAL_MACHINE ",
"HEKY_USERS ",
"HEKY_CURRENT_CONFIG "};
char data_set[1024];
DWORD nCount = 0; // calculate the keys number
void EnumValue(HKEY hKey)
{
int dwIndex = 0;
char valuename[MAX_PATH + 1];
DWORD valuenamelen;
DWORD Type;
union{
BYTE data[1024];
DWORD idata;
}lpdata;
DWORD datalen;
valuenamelen = sizeof(valuename);
datalen = sizeof(lpdata);
memset(&lpdata,0,sizeof(lpdata));
while(::RegEnumValue (hKey,dwIndex,(LPTSTR)valuename,&valuenamelen,
0,&Type,lpdata.data,&datalen) != ERROR_NO_MORE_ITEMS)
{
switch(Type)
{
case REG_SZ:
printf( "value:\t%s\tdata:\t%s\n ",valuename,(char*)lpdata.data);
break;
case REG_DWORD:
printf( "value:\t%sdata:\t%ld\n ",valuename,lpdata.idata);
break;
default:
break;
}
dwIndex ++;
valuenamelen = sizeof(valuename);
datalen = sizeof(lpdata);
memset(&lpdata,0,sizeof(lpdata));
}
}
void EnumKey(HKEY hKey,char *sKey)
{
HKEY h;
int dwIndex = 0;
char strkey[2048];
char name[1024] = {0};
DWORD namelen = sizeof(name);
FILETIME ftLastWriteTime;
if(::RegOpenKeyEx (hKey,(LPTSTR)data_set,0,KEY_READ,&h) != ERROR_SUCCESS)
{
printf( "cann 't open key %s!\n ",strkey);
return;
}
while(::RegEnumKeyEx (h,dwIndex,name,&namelen,0,NULL,NULL,&ftLastWriteTime) != ERROR_NO_MORE_ITEMS)
{
EnumValue(h);
nCount ++;
printf( "%s\\%s\n ",sKey,name);
Sleep(100);
HKEY hk;
if(::RegOpenKeyEx (h,(LPTSTR)name,0,KEY_READ,&hk) == ERROR_SUCCESS)
{
strcpy(data_set, " ");
strcpy(strkey,sKey);
strcat(strkey, "\\ ");
strcat(strkey,name);
EnumKey(hk,strkey);
::RegCloseKey (hk);
}
dwIndex += 1;
namelen = sizeof(name); //must be specified every time!!!
}
::RegCloseKey (hKey);
}
void main()
{
printf( "Enum all reg keys and values\n ");
time_t start,end;
time(&start);
for(int i = 0 ; i < 5; i++)
{
strcpy(data_set, " ");
EnumKey(hKey[i],sKey[i]);
}
time(&end);
printf( "altogether %ld keys!!!\n ",nCount);
printf( "using time : %ld seconds!\n ",end - start );
}
*****************************************************************
3.下面是我改写的,可以用
HKEY hKey;
long lon = RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Internet Explorer\\TypedURLs", 0, KEY_READ,&hKey);
vector<string> vecStrUrls ;
int dwIndex = 0 ;
char szValueName[MAX_PATH] = {0} ;
DWORD dwValueVameLen = MAX_PATH ;
DWORD dwType;
union
{
BYTE data[1024];
DWORD idata;
}lpdata;
DWORD dwDataLen = sizeof(lpdata);
DWORD Type ;
memset(&lpdata, 0, sizeof(lpdata));
while(RegEnumValue(hKey, dwIndex, (LPTSTR)szValueName, &dwValueVameLen, 0, &Type, lpdata.data, &dwDataLen) != ERROR_NO_MORE_ITEMS)
{
switch(Type)
{
case REG_SZ:
vecStrUrls.push_back((char*)lpdata.data) ; // 必须要转下,因为 BYTE(unsigned char) 和 char 是不可以默认转的。
break;
default:
break;
}
dwIndex++;
dwValueVameLen = sizeof(szValueName);
dwDataLen = sizeof(lpdata);
memset(&lpdata, 0, sizeof(lpdata));
}
RegCloseKey(hKey) ;