c 使用API判斷網路是否連通

2021-09-22 09:50:52 字數 1218 閱讀 3813

#include "stdafx.h"

#include "test.h"

#include

#include

#ifdef _debug

#define new debug_new

#undef this_file

static char this_file = __file__;

#endif

using namespace std;

m_bonline=internetgetconnectedstate(&flags,0);

m_bonline=isnetworkalive(&flags);

int _tmain(int argc, tchar* ar**, tchar* envp)

說明:internetgetconnectedstate():對網路狀況不能及時反應

isnetworkalive()/networkchange可以及時反應網路連通情況,但是需要服務system event notification支援(系統預設自動啟動該服務)。使用該函式,需要安裝最新的sdk(如.net的)

微軟文件:

system event notification(sens) 服務監視並跟蹤計算機事件(如 windows 登入網路和電源事件)。它還將這些事件通知給com+ 事件系統訂閱者。在 windows xp 和 windows server 2003 上預設安裝並自動執行此服務。

如果system event notification服務停止,com+ event system服務的訂閱者將不會接收到事件通知,並且會發生以下問題:

•win32 api isnetworkalive() 和 isdestinationreachable() 將無法執行。這些 api 大多在可攜式計算機的移動應用程式中使用。

•isens* 介面將無法使用。sens 登入/登出通知將失敗。

•syncmgr (mobsync.exe) 將無法正常執行。syncmgr 依賴於連線資訊,以及來自 sens 的網路連線/斷開、登入/登出通知。

•com+ eventsystem 試圖向 sens 通知某些事件時將失敗。

volume shadow copy服務將不能正常載入,這將導致 windows 備份 api 失敗。

c 判斷網路是否連線

win32 api函式的做法 要用的函式 internetgetconnectedstate 函式原形 bool internetgetconnectedstate lpdword lpdwflags,dword dwreserved 引數lpdwflags返回當前網路狀態,引數dwreserved...

C 判斷檢測網路是否連線

完整的 using system.runtime.interopservices namespace internet public class class1 dllimport wininet.dll private extern static bool internetgetconnecteds...

判斷網路是否可用

這段 用於判斷網路是否可用,如果不可用則開啟網路設定,設定網路連線,當然也可以忽略設定,即不做處理。connectivitymanager connectmanager connectivitymanager this.getsystemservice connectivity service if...