Results 1 to 2 of 2

Thread: LAN/WLAN Switch

  1. #1
    Senior Member
    Join Date
    Jul 2003

    LAN/WLAN Switch

    I have a pc with LAN i WLAN network cards. I want to make a c++/perl/pascal program that enable/disable the WLAN card when the LAN cable is disconnected/connected. Can anybody help me with some solution, api, source or something ... The OS is Windows XP.

    [gloworange] [/gloworange]

  2. #2
    Senior Member
    Join Date
    Mar 2004

    I am lacking a bit time, so I will not provide a
    out-of-the-box solution, sorry.

    How to enable/disable a network interface?

    In this article[1], several ways are presented to
    enable/disable a network interface programmatically.
    I would use shell network interfaces.
    Note that the Iphelper-API administrative enabling/
    disabling is not equivalent to enable/disable the
    interface in the network neighborhood. Furthermore,
    with Iphelper you cannot access a disabled interface.

    How to check the status of a network interface?

    The Iphelper-API is exactly what you need. The
    snippet is taken from[2] with a
    few modifications of myself at the end.

    // Declare and initialize variables.
    PMIB_IFTABLE ifTable;
    PMIB_IFROW pMibIfRow;
    DWORD dwSize = 0;
    DWORD dwRetVal = 0;
    int enumEntry;
    // Allocate memory for our pointers.
    ifTable = (MIB_IFTABLE*) malloc(sizeof(MIB_IFTABLE));
    pMibIfRow = (MIB_IFROW*) malloc(sizeof(MIB_IFROW));
    // Before calling GetIfEntry, we call GetIfTable to make
    // sure there are entries to get.
    // Make an initial call to GetIfTable to get the
    // necessary size into dwSize
    if (GetIfTable(ifTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {
      ifTable = (MIB_IFTABLE *) malloc (dwSize);
    // Make a second call to GetIfTable to get the actual
    // data we want.
     if ((dwRetVal = GetIfTable(ifTable, &dwSize, 0)) == NO_ERROR) {
    	for (enumEntry=0;enumEntry<ifTable->dwNumEntries;enumEntry++){
    		printf("Interface Index: %d\n",ifTable->table[enumEntry].dwIndex);
    		pMibIfRow->dwIndex = ifTable->table[enumEntry].dwIndex;
    		if ((dwRetVal = GetIfEntry(pMibIfRow)) == NO_ERROR) {
    		  printf("\tDescription: %s\n", pMibIfRow->bDescr);
    		  printf("\tStatus: %d\n", pMibIfRow->dwOperStatus);
    		else {
    		  printf("GetIfEntry failed.\n");
    		  // Here you can use FormatMessage to find out why 
    		  // it failed.
    The operation status dwOperStatus is also enumerated on microsoft[3].
    E.g. Status "5" is connected.

    Combine the two, then you have your little program.


    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts