在 UWP 应用程序上使用 VB.net 获取 IPGlobalProperties
Getting IPGlobalProperties with VB.net on a UWP application
我正在 Visual Studio 2017 年使用 VB 编写一个非常简单的通用 Windows 应用程序。
该应用程序应向用户提供基本网络信息,因此我想使用 IPGlobalProperties
收集数据并打印(作为第一个示例)名为 textDomain
[=16 的 TextBlock 中的 DomainName
=]
Dim NetworkProperties As NetworkInformation.IPGlobalProperties
NetworkProperties = NetworkInformation.IPGlobalProperties.GetIPGlobalProperties
textDomain.Text = NetworkProperties.DomainName
虽然在前两行代码中正确分配了属性,但第三行代码导致错误 System.PlatformNotSupportedException: 'Operation is not supported on this platform.'
我在经典 Windows 应用程序上尝试了相同的代码并且它按预期工作,那么通用应用程序不支持此操作吗?
如果是,我应该使用什么方法来获取有关网络的相同信息?
感谢您提供的任何帮助
卢卡
首先,IPGlobalProperties
class is not supported in uwp app. Since.NET for UWP apps provides a set of managed types that you can use to create Universal Windows Platform apps, but not the all. Details please reference .NET for UWP apps. System.Net
命名空间可以在 uwp 应用程序中使用,但 IPGlobalProperties
不能。
其次,您可以在 uwp 应用程序中找到等效或相似的 API。例如,您还可以找到 NetworkInformation
in uwp which is belong to Windows.Networking.Connectivity
namespace. But invoking the methods of this class is not the same way with the System.Net.NetworkInformation
命名空间。
如果想像IPGlobalProperties
那样获取计算机名或域名,可以调用GetHostNames()
方法。代码如下:
Imports Windows.Networking.Connectivity
''' <summary>
''' An empty page that can be used on its own or navigated to within a Frame.
''' </summary>
Public NotInheritable Class MainPage
Inherits Page
Private Sub btngetinfo_Click(sender As Object, e As RoutedEventArgs)
Dim hostNames = NetworkInformation.GetHostNames()
textDomain.Text = hostNames.First.ToString
End Sub
End Class
我正在 Visual Studio 2017 年使用 VB 编写一个非常简单的通用 Windows 应用程序。
该应用程序应向用户提供基本网络信息,因此我想使用 IPGlobalProperties
收集数据并打印(作为第一个示例)名为 textDomain
[=16 的 TextBlock 中的 DomainName
=]
Dim NetworkProperties As NetworkInformation.IPGlobalProperties
NetworkProperties = NetworkInformation.IPGlobalProperties.GetIPGlobalProperties
textDomain.Text = NetworkProperties.DomainName
虽然在前两行代码中正确分配了属性,但第三行代码导致错误 System.PlatformNotSupportedException: 'Operation is not supported on this platform.'
我在经典 Windows 应用程序上尝试了相同的代码并且它按预期工作,那么通用应用程序不支持此操作吗?
如果是,我应该使用什么方法来获取有关网络的相同信息?
感谢您提供的任何帮助
卢卡
首先,IPGlobalProperties
class is not supported in uwp app. Since.NET for UWP apps provides a set of managed types that you can use to create Universal Windows Platform apps, but not the all. Details please reference .NET for UWP apps. System.Net
命名空间可以在 uwp 应用程序中使用,但 IPGlobalProperties
不能。
其次,您可以在 uwp 应用程序中找到等效或相似的 API。例如,您还可以找到 NetworkInformation
in uwp which is belong to Windows.Networking.Connectivity
namespace. But invoking the methods of this class is not the same way with the System.Net.NetworkInformation
命名空间。
如果想像IPGlobalProperties
那样获取计算机名或域名,可以调用GetHostNames()
方法。代码如下:
Imports Windows.Networking.Connectivity
''' <summary>
''' An empty page that can be used on its own or navigated to within a Frame.
''' </summary>
Public NotInheritable Class MainPage
Inherits Page
Private Sub btngetinfo_Click(sender As Object, e As RoutedEventArgs)
Dim hostNames = NetworkInformation.GetHostNames()
textDomain.Text = hostNames.First.ToString
End Sub
End Class