JAGUARSDN1网络的开机自动启动 禁用,WIFI模块的启动关闭控制

先确认下系统中有没有加载NDISPWR.DLL,如果没有的话,把这个组件加上

WIFI在默认情况下,是开机自动打开的,如果要开机禁用,在HKEY_LOCAL_MACHINE/Comm/NdisPower创建一个键值

name = 4

name是你用的WIFI的名字

如果想开机自动打开,把这个键值删掉

打开关闭WIFI时,想网络图标正常,除了用setdevicepower外
还要用到NDIS的IOCTL_NDIS_BIND_ADAPTER或者IOCTL_NDIS_UNBIND_ADAPTER
绑定或者解除绑定

 

在HKEY_LOCAL_MACHINE/Comm/NdisPower下面加"JaguarSDN1" = 4 就OK了

IOCTL_NDIS_BIND_ADAPTER是用DeviceIoControl操作的,打开的设备是NDS0,bufferin里写你要bind的网卡名字,因为网卡是NDIS设备,网卡名字应该是NDIS的ClassID+JaguarSDN1

具体代码去PUBLIC下找NDISPWR的代码看看

 

 

===============================================

BOOL 
DoNdisIOControl(
  DWORD dwCommand, 
  LPVOID pInBuffer,
  DWORD cbInBuffer, 
  LPVOID pOutBuffer,
  DWORD *pcbOutBuffer)
{
  HANDLE hNdis;
  BOOL bResult = FALSE;

  hNdis = CreateFile(
  DD_NDIS_DEVICE_NAME, 
  GENERIC_READ | GENERIC_WRITE,
  FILE_SHARE_READ | FILE_SHARE_WRITE, 
  NULL, 
  OPEN_ALWAYS,
  0, 
  NULL);

  if (INVALID_HANDLE_VALUE != hNdis)
  {
  bResult = DeviceIoControl(
  hNdis, 
  dwCommand, 
  pInBuffer, 
  cbInBuffer,
  pOutBuffer, 
  (pcbOutBuffer ? *pcbOutBuffer : 0x00),
  pcbOutBuffer, 
  NULL);
   
  CloseHandle(hNdis);
  }

  return bResult;
   
}




  nChars = _sntprintf(
  szName, 
  MAX_PATH-1, 
  _T("%s//%s"), 
  PMCLASS_NDIS_MINIPORT, 
  ptcDeviceName);


  if (nChars != -1)
  {
  DEBUGMSG (ZONE_NDISUIO,
  (TEXT("NdisPower:: Setting adapter [%s] to Power State [%s]./r/n"),
  ptcDeviceName,
  (CePowerState == D0) ? TEXT("D0") :
  (CePowerState == D1) ? TEXT("D1") :
  (CePowerState == D2) ? TEXT("D2") :
  (CePowerState == D3) ? TEXT("D3") :
  (CePowerState == D4) ? TEXT("D4") :
  (CePowerState == PwrDeviceUnspecified) ? TEXT("PwrDeviceUnspecified") :  
  TEXT("UNKNOWN!")));

  SetDevicePower(szName, POWER_NAME, CePowerState);

  }

  //
  // IOCTL_NDIS_UNBIND_ADAPTER takes multisz (protocol driver names
  // follow the adapter name) hence we need extra NULL.
  //
   
  memset (szName, 0x00, sizeof(szName));
  _tcscpy(szName, ptcDeviceName);
  DoNdisIOControl(
  IOCTL_NDIS_UNBIND_ADAPTER, 
  szName,
  (_tcslen(ptcDeviceName)+2) * sizeof(TCHAR),
  NULL, 
  NULL); 

这段是先关设备再UNBIND的代码,希望对你有帮助

你可能感兴趣的:(WINCE,网络,null,file)