How can i start my application when network connection is available?

prashant_sharma

I am installing a service using installshield. This service is configured to get started when the user restarts the system or logs in. Now i need to start the app when network connection is available in the PC. Is there any way in which this can be done??

Thanks!

Jochen Kalmbach

To check for network connection, you can call IsNetworkAlive. Here is an example:

#include <stdio.h>
#include <tchar.h>
#include <Windows.h>
#include <Sensapi.h>
#pragma comment(lib, "Sensapi.lib")

int _tmain(int argv, char *argc[]) 
{ 
  DWORD dwSens;
  if (IsNetworkAlive(&dwSens) == FALSE)
  {
    printf("No network connection");
  }
  else
  {
    switch(dwSens)
    {
    case NETWORK_ALIVE_LAN:
      printf("LAN connection available");
      break;
    case NETWORK_ALIVE_WAN:
      printf("WAN connection available");
      break;
    default:
      printf("Unknown connection available");
      break;
    }
  }
  return 0; 
} 

Starting with Vista, you can also take a look at the Network list manager. This will give you a more detailed answer:

You cann call the method INetworkListManager::GetConnectivity to check for network connectivity:

#include <stdio.h>
#include <tchar.h>
#include <Windows.h>
#include <Netlistmgr.h>
#include <atlbase.h>

int _tmain(int argv, char *argc[]) 
{ 
  printf("\n");

  CoInitialize(NULL);
  {
    CComPtr<INetworkListManager> pNLM;
    HRESULT hr = CoCreateInstance(CLSID_NetworkListManager, NULL, 
      CLSCTX_ALL, __uuidof(INetworkListManager), (LPVOID*)&pNLM);
    if (SUCCEEDED(hr))
    {
      NLM_CONNECTIVITY con = NLM_CONNECTIVITY_DISCONNECTED;
      hr = pNLM->GetConnectivity(&con);
      if SUCCEEDED(hr)
      {
        if (con & NLM_CONNECTIVITY_IPV4_INTERNET)
          printf("IP4: Internet\n");
        if (con & NLM_CONNECTIVITY_IPV4_LOCALNETWORK)
          printf("IP4: Local\n");
        if (con & NLM_CONNECTIVITY_IPV4_SUBNET)
          printf("IP4: Subnet\n");
        if (con & NLM_CONNECTIVITY_IPV6_INTERNET)
          printf("IP6: Internet\n");
        if (con & NLM_CONNECTIVITY_IPV6_LOCALNETWORK)
          printf("IP6: Local\n");
        if (con & NLM_CONNECTIVITY_IPV6_SUBNET)
          printf("IP6: Subnet\n");
      }
    }
  }
  CoUninitialize();
  return 0; 
} 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why can't I start my gunicorn server? "Connection in use"

From Dev

Can I start an activity as a new Application or outside my app?

From Dev

How can I troubleshoot a network share connection issue within a c# application?

From Dev

how can I detect deadlocks in MySQL? What could cause my application to hang when making a connection?

From Dev

Can I have something like this when no internet connection is available?

From Dev

my application stops when I start it

From Dev

how can I make my image (down arrow) disappear when I start scrolling my page?

From Dev

How can I make the application package available to the tests, when using py.test?

From Dev

how many default number of partition there are when I initially start my spark application

From Dev

How do I stop my ethernet network connection from dropping?

From Dev

How do I reset everything in regards to my network connection?

From Dev

How can I configure the network on my Kubuntu box to be a system connection

From Dev

How do I stop my ethernet network connection from dropping?

From Dev

How can I find available network interfaces?

From Dev

How do I reset everything in regards to my network connection?

From Dev

How can I set a network connection as metered?

From Dev

How can I have transmission start automatically when I open my computer?

From Dev

Why can I not access the internet when Windows 7 finds no issue with the ethernet connection and the network can see my device?

From Dev

Can I have something like this when no internet connection is available?

From Dev

How can I make Rasdial execute again if a connection is not yet available?

From Dev

How can I make my tftp server visible/available on my local network?

From Dev

How can i manage my Ble connection?

From Dev

How can I automatically start an SSH tunnel when I put in my Pageant password?

From Dev

How can I use application-scoped resources when my application builds as 'Page' and not 'Application Definition'?

From Dev

How can I access servers on my network when connected to a VPN?

From Dev

How can I know if an RDP connection is available?

From Dev

How can I start my application in a more convenient way?

From Dev

How can I read from a network path on my server using asp.net mvc application

From Dev

How can I use an application class in order to start a service and use it in my activities?

Related Related

  1. 1

    Why can't I start my gunicorn server? "Connection in use"

  2. 2

    Can I start an activity as a new Application or outside my app?

  3. 3

    How can I troubleshoot a network share connection issue within a c# application?

  4. 4

    how can I detect deadlocks in MySQL? What could cause my application to hang when making a connection?

  5. 5

    Can I have something like this when no internet connection is available?

  6. 6

    my application stops when I start it

  7. 7

    how can I make my image (down arrow) disappear when I start scrolling my page?

  8. 8

    How can I make the application package available to the tests, when using py.test?

  9. 9

    how many default number of partition there are when I initially start my spark application

  10. 10

    How do I stop my ethernet network connection from dropping?

  11. 11

    How do I reset everything in regards to my network connection?

  12. 12

    How can I configure the network on my Kubuntu box to be a system connection

  13. 13

    How do I stop my ethernet network connection from dropping?

  14. 14

    How can I find available network interfaces?

  15. 15

    How do I reset everything in regards to my network connection?

  16. 16

    How can I set a network connection as metered?

  17. 17

    How can I have transmission start automatically when I open my computer?

  18. 18

    Why can I not access the internet when Windows 7 finds no issue with the ethernet connection and the network can see my device?

  19. 19

    Can I have something like this when no internet connection is available?

  20. 20

    How can I make Rasdial execute again if a connection is not yet available?

  21. 21

    How can I make my tftp server visible/available on my local network?

  22. 22

    How can i manage my Ble connection?

  23. 23

    How can I automatically start an SSH tunnel when I put in my Pageant password?

  24. 24

    How can I use application-scoped resources when my application builds as 'Page' and not 'Application Definition'?

  25. 25

    How can I access servers on my network when connected to a VPN?

  26. 26

    How can I know if an RDP connection is available?

  27. 27

    How can I start my application in a more convenient way?

  28. 28

    How can I read from a network path on my server using asp.net mvc application

  29. 29

    How can I use an application class in order to start a service and use it in my activities?

HotTag

Archive