[Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]‘{DCB00C01-570F- 4A9B-8D69-199FDBA5723B}’)).IsConnectedToInternet
http://blogs.msdn.com/powershell/archive/2009/04/03/setting-network-location-to-private.aspx
我从上面的源代码中找到了这个PowerShell代码,然而它按预期工作 我想让它在VB.NET中工作以检查Internet连接。其中之一 专家协助,因为我到目前为止无法管理它?
答案 0 :(得分:2)
这是底层wininet API的简单接口。
Private Declare Function InternetGetConnectedState Lib "wininet.dll" _
(ByRef lpdwFlags As Int32, ByVal dwReserved As Int32) As Boolean
Public Shared Function IsConnectedToInternet( ) As Boolean
Try
Dim flags as Integer;
return InternetGetConnectedState(flags, 0)
Catch
return False
End Try
End Function
请参阅PInvoke.net