电脑有三块网卡,网卡IP地址都不同,现在要实现根据IP地址灵活启用和禁用其中的一块或几块如何用VC实现。
求救!
求救!
解决方案 »
- 窗体实现问题
- 基于实时阴影线渲染的阴影技术???
- 求助,怎样使用string?
- 郁闷,散分,准备辞职
- 用MFC开发的ACTIVEX控件,怎样取得本控件所在的IE窗口的句柄。从而使这个IE窗口从最小化形式变成最大化形式。
- 在ASP中获取远程客户端IP用ServerVariable("REMOTE_ADDR"),如果有代理服务器的话,只能获得代理服务器的IP,现在要通过程序方法绕过代理
- 如何传递自定义类型的指针???
- 会PASCAL,想转学C++之后VC,有什么好书或相关资料?
- 注册表的问题,小小问题大家来呀
- 百度杀毒老是要修复,怎么办?
- 关于3DES加密
- 开启一个work线程后主界面不能响应键盘消息,但能接受鼠标,为什么?
#include
#include
#include #pragma comment (lib,"setupapi")#define UnknownDevice TEXT("")HDEVINFO hDevInfo = 0;
BOOL StateChange(DWORD NewState, DWORD SelectedItem,HDEVINFO hDevInfo)
{
SP_PROPCHANGE_PARAMS PropChangeParams = {sizeof(SP_CLASSINSTALL_HEADER)};
SP_DEVINFO_DATA DeviceInfoData = {sizeof(SP_DEVINFO_DATA)};
HCURSOR hCursor;//
// This may take a while :^(
//
hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));//
// Get a handle to the Selected Item.
//
if (!SetupDiEnumDeviceInfo(hDevInfo,SelectedItem,&DeviceInfoData))
{
printf("EnumDeviceInfo");
return FALSE;
}//
// Set the PropChangeParams structure.
//
PropChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
PropChangeParams.Scope = DICS_FLAG_GLOBAL;
PropChangeParams.StateChange = NewState; if (!SetupDiSetClassInstallParams(hDevInfo,
&DeviceInfoData,
(SP_CLASSINSTALL_HEADER *)&PropChangeParams,
sizeof(PropChangeParams)))
{
printf("SetClassInstallParams");
SetCursor(hCursor);
return FALSE;
}//
// Call the ClassInstaller and perform the change.
//
if (!SetupDiCallClassInstaller(DIF_PROPERTYCHANGE,
hDevInfo,
&DeviceInfoData))
{
printf("SetClassInstallParams");
SetCursor(hCursor);
return TRUE;
}SetCursor(hCursor);
return TRUE;
}
BOOL IsClassNet( GUID * ClassGuid )
{
#define MAX_NUM 50HKEY hKeyClass;
LONG lRet;
char ClassType[MAX_NUM];
char NetClass[MAX_NUM] = "Net";
DWORD dwLength = MAX_NUM,dwType = REG_SZ;if (hKeyClass = SetupDiOpenClassRegKey(ClassGuid,KEY_READ))
{
lRet = RegQueryValueEx(hKeyClass,
TEXT("Class"),
NULL, &dwType, LPBYTE(ClassType), &dwLength);
RegCloseKey(hKeyClass);if (lRet != ERROR_SUCCESS)
return FALSE;if (!strcmp(ClassType,NetClass))
return TRUE;
} return FALSE;
}int main(int argc, char* argv[])
{
if (INVALID_HANDLE_VALUE == (hDevInfo =
SetupDiGetClassDevs(NULL,NULL,0,
DIGCF_PRESENT|DIGCF_ALLCLASSES)))
{
printf("GetClassDevs");
return 0;
}DWORD i, Status, Problem;
SP_DEVINFO_DATA DeviceInfoData = {sizeof(SP_DEVINFO_DATA)};HKEY hKeyClass;
char DeviceName[200];
for (i=0;SetupDiEnumDeviceInfo(hDevInfo,i,&DeviceInfoData);i++)
{
if (IsClassNet(&DeviceInfoData.ClassGuid))
{
printf(" the class‘s index is %d\n",i);
//
//DICS_DISABLE-->禁用网络
//DICS_ENABLE--->恢复网络
//
if (StateChange(DICS_ENABLE,i,hDevInfo))
printf("NetWork stopped");}
}return 0;
}