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??
我正在使用installshield安装服务。此服务配置为在用户重新启动系统或登录时启动。现在我需要在PC中有网络连接时启动应用程序。有什么办法可以做到这一点?
Thanks!
谢谢!
3 个解决方案
#1
2
To check for network connection, you can call IsNetworkAlive. Here is an example:
要检查网络连接,可以调用IsNetworkAlive。这是一个例子:
#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:
从Vista开始,您还可以查看网络列表管理器。这将为您提供更详细的答案:
You cann call the method INetworkListManager::GetConnectivity to check for network connectivity:
您可以调用方法INetworkListManager :: GetConnectivity来检查网络连接:
#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;
}
#2
0
You can try to ping a website for example google which is 99,99% Online and react to a boolean value.
您可以尝试ping一个网站,例如google,这是99,99%Online并对布尔值做出反应。
#3
0
Modify and tell your service for the network avilablity every second, as it arrives into your system, do whatever you want in your code.
每秒修改并告诉您的服务网络可用性,因为它到达您的系统,在您的代码中做任何您想做的事情。
Also, you can create a exe with a timer contorl and on regular interval poll for internet/network connection
此外,您可以创建一个具有计时器控制的exe和定期间隔轮询的互联网/网络连接
#1
2
To check for network connection, you can call IsNetworkAlive. Here is an example:
要检查网络连接,可以调用IsNetworkAlive。这是一个例子:
#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:
从Vista开始,您还可以查看网络列表管理器。这将为您提供更详细的答案:
You cann call the method INetworkListManager::GetConnectivity to check for network connectivity:
您可以调用方法INetworkListManager :: GetConnectivity来检查网络连接:
#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;
}
#2
0
You can try to ping a website for example google which is 99,99% Online and react to a boolean value.
您可以尝试ping一个网站,例如google,这是99,99%Online并对布尔值做出反应。
#3
0
Modify and tell your service for the network avilablity every second, as it arrives into your system, do whatever you want in your code.
每秒修改并告诉您的服务网络可用性,因为它到达您的系统,在您的代码中做任何您想做的事情。
Also, you can create a exe with a timer contorl and on regular interval poll for internet/network connection
此外,您可以创建一个具有计时器控制的exe和定期间隔轮询的互联网/网络连接