檢測本地計算機是否連上Internet

[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState( out int connectionDescription, int reservedValue ) ;

/// <summary>
/// Retrieves the connected state of the local system.
/// </summary>
/// <returns>Returns True if there is an Internet connection, or False otherwise.</returns>
public bool IsConnected()
{
    int connectionDescription = 0;
    return InternetGetConnectedState(out connectionDescription, 0);
}

References:
Microsoft Offline Application Block
WinINetDetectionStrategy.cs

發佈了78 篇原創文章 · 獲贊 0 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章