现在的位置: 首页 > 综合 > 正文

win32 查找注册表找网卡

2018年05月08日 ⁄ 综合 ⁄ 共 1798字 ⁄ 字号 评论关闭
#define SIZEOF_DEVICE_NAME  256

CString strDeviceList = "";

BOOL get_device_info(int Index,
					 char *key_name,
					 char *device_info,
					 char *device_description)
{
	HKEY hkey ;
	DWORD size ;
	DWORD type ;
	BOOL retval ;

	retval = FALSE ;
	memset( device_info, 0, SIZEOF_DEVICE_NAME) ;

	if( RegOpenKeyExA(HKEY_LOCAL_MACHINE,
		              key_name,
                      0,
                      KEY_READ,
                      &hkey) == ERROR_SUCCESS)
	{
		type = REG_SZ ;
		size = SIZEOF_DEVICE_NAME ;

		if( RegQueryValueExA(hkey,
                             "ServiceName",
                             NULL,
                             &type,
                             ( BYTE *) device_info,
                             &size) == ERROR_SUCCESS)
		{
			type = REG_SZ ;
			size = SIZEOF_DEVICE_NAME ;

			
			if( RegQueryValueExA(hkey,
                                 "Description",
                                 NULL,
                                 &type,
                                 ( BYTE *) device_description,
                                 &size) == ERROR_SUCCESS)
			{
				retval = TRUE ;

			}
		}
        
		RegCloseKey( hkey) ;
	}
    
	return retval ;
}

BOOL list_devices( void)
{
	char key_name[ SIZEOF_DEVICE_NAME] = {0} ;
	char full_name[ SIZEOF_DEVICE_NAME] = {0} ;
	char device_info[ SIZEOF_DEVICE_NAME] = {0} ;
	char device_description[ SIZEOF_DEVICE_NAME] = {0} ;

	
	strDeviceList = "";
	
	FILETIME file_time ;
	
	HKEY hkey ;
	int index ;
	DWORD size ;
    
	index = 0 ;
	
	if( RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards",
                    0,
                    KEY_READ,
                    &hkey) == ERROR_SUCCESS)
	{
		size = SIZEOF_DEVICE_NAME ;
        
		while( RegEnumKeyExA(hkey,
			                  index,
                             key_name,

                             &size,
                             NULL,
                             NULL,
                             NULL,
                             &file_time) == ERROR_SUCCESS)
		{
			sprintf(full_name,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards\\%s", key_name) ;
			
			get_device_info(index,
				full_name,
				device_info,
				device_description) ;
			
			CString strDevice = "";
			strDevice.Format( 
			    "Index=%d\r\n\tName=%s\r\n\tDesc=%s\r\n\t"
			    "Key=%s\r\n\r\n",
			    index + 1,
			    device_info,
			    device_description,
			    full_name) ;
			strDeviceList += strDevice;
			index++ ;
			size = SIZEOF_DEVICE_NAME ;
		}
		RegCloseKey( hkey) ;
	}
	if( index == 0)
	{
		return false;// printf( "No devices found\n\n") ;
	}
    
	return TRUE ;
}

void main()
{
    list_devices();
    print("%s", strDeviceList);
}

在使用DeviceIoControl关联到我们的NdisDevice设备的时候又错误了。原因是无法关联到该设备,为什么?因为你的设别名称填写错误。
1.用注册表看。
2装了winpcap的人可以使用winpcap查看。其形状如:\Devce\NPF_{xxxxxxxxx} ;
又来一个NdisDevice设备名称,这个才是真正的硬件设备名称。怎么看?

抱歉!评论已关闭.