下面这段代码在xp下是可以正确的disable掉指定的网卡的
但是在vista下,尽管所有的API返回都正确
却无法把网卡disable
请问大侠在vista下是否不能用这种办法
或者还有其他的办法达到相同的功能,谢谢!!hDevInfo = SetupDiGetClassDevs(NULL, NULL, hwndParent, DIGCF_PRESENT|DIGCF_ALLCLASSES);
// retrieves a context structure for a device information element of the specified device
// information set.
for (i= 0; SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData); i++)
{
if (SetupDiGetDeviceRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_DEVICEDESC, NULL,
(UCHAR*)&szDesc[0], sizeof(szDesc)-1,
&dwRet))
{
if (!strcmp(szDesc, (char*)strDesc)) // Found Device
{
// Set the PropChangeParams structure to Disable.
PropChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
PropChangeParams.Scope = DICS_FLAG_CONFIGSPECIFIC;
PropChangeParams.StateChange = DICS_DISABLE; if (SetupDiSetClassInstallParams(hDevInfo, &DeviceInfoData, (SP_CLASSINSTALL_HEADER *)&PropChangeParams,
sizeof(PropChangeParams)))
{
// Call the ClassInstaller and perform the change.
if (SetupDiCallClassInstaller( DIF_PROPERTYCHANGE, hDevInfo,&DeviceInfoData))
{
}}
但是还是不行
如果不是管理员身份
API会返回失败的(access deny)