在windows下获得网卡状态。(急!在线等) 在windows下利用程序获得网卡状态,(启用,禁止等)。我先谢谢大家了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这是完整的可运行程序。#include <windows.h> #include <stdio.h>#include <tchar.h> // Make program ansi AND unicode safeextern "C"{#include <setupapi.h> // Used for SetupDiXxx functions#include <devguid.h>#include <cfgmgr32.h> // Used for CM_Xxxx functions}#pragma comment (lib,"setupapi")#pragma comment (lib,"cfgmgr32")HDEVINFO hDevInfo = 0;// 设备是否处于禁用状态BOOL IsDisabled( PSP_DEVINFO_DATA pDevInfoData, HDEVINFO hDevInfo ){ DWORD Status, Problem; if (CR_SUCCESS != CM_Get_DevNode_Status(&Status, &Problem, pDevInfoData->DevInst, 0)) { _tprintf("Get_DevNode_Status() failed.\r\n"); return FALSE; } return ((Status & DN_HAS_PROBLEM) && (CM_PROB_DISABLED == Problem)) ;}int main(int argc, char* argv[]){ hDevInfo = SetupDiGetClassDevs( (LPGUID)&GUID_DEVCLASS_NET, NULL, 0, DIGCF_PRESENT); BOOL bRet = FALSE; char DeviceName[255]; SP_DEVINFO_DATA DeviceInfoData = {sizeof(SP_DEVINFO_DATA)}; for (DWORD i=0; SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData); i++) { // 得到设备名 if ( SetupDiGetDeviceRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_DEVICEDESC, NULL, (PBYTE) DeviceName, MAX_PATH, NULL) ) { printf("DeviceName = %s\n", DeviceName); } bRet = IsDisabled(&DeviceInfoData, hDevInfo); printf("Device State = %s\r\n", bRet ? "Disable" : "Enable"); printf("\r\n"); } getchar(); return 0;} 确实如此,但Windows系统是只和网卡设备直接相联的。 IplImage类型如何转化为Image 麻烦驱动高手进来留个QQ号,随后开贴重分相谢 能用VS2003在XP环境下开发应用程序的jumplist吗? 在StdAfx头文件中引用ADO库文件的问题 关于多线程 怎样将DDB转化为DIB 调查:汉字在信息处理方面有什么劣势? 不规则对话框如何改变大小! 一个DLL,里面要创建一个窗体,可是在调用AfxGetInstanceHandle就会ASSERT失败?在线等待 文件删除操作问题~~ 鼠标消息如何截获 如何将CImageList中的一项转换成CBitmap?
#include <stdio.h>
#include <tchar.h> // Make program ansi AND unicode safe
extern "C"
{
#include <setupapi.h> // Used for SetupDiXxx functions
#include <devguid.h>
#include <cfgmgr32.h> // Used for CM_Xxxx functions
}#pragma comment (lib,"setupapi")
#pragma comment (lib,"cfgmgr32")
HDEVINFO hDevInfo = 0;// 设备是否处于禁用状态
BOOL IsDisabled( PSP_DEVINFO_DATA pDevInfoData, HDEVINFO hDevInfo )
{
DWORD Status, Problem;
if (CR_SUCCESS != CM_Get_DevNode_Status(&Status, &Problem, pDevInfoData->DevInst, 0))
{
_tprintf("Get_DevNode_Status() failed.\r\n");
return FALSE;
}
return ((Status & DN_HAS_PROBLEM) && (CM_PROB_DISABLED == Problem)) ;
}int main(int argc, char* argv[])
{
hDevInfo = SetupDiGetClassDevs(
(LPGUID)&GUID_DEVCLASS_NET,
NULL,
0,
DIGCF_PRESENT);
BOOL bRet = FALSE;
char DeviceName[255];
SP_DEVINFO_DATA DeviceInfoData = {sizeof(SP_DEVINFO_DATA)}; for (DWORD i=0; SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData); i++)
{
// 得到设备名
if ( SetupDiGetDeviceRegistryProperty(hDevInfo,
&DeviceInfoData, SPDRP_DEVICEDESC, NULL, (PBYTE) DeviceName, MAX_PATH, NULL) )
{
printf("DeviceName = %s\n", DeviceName);
} bRet = IsDisabled(&DeviceInfoData, hDevInfo);
printf("Device State = %s\r\n", bRet ? "Disable" : "Enable");
printf("\r\n");
}
getchar();
return 0;
}