Getting IPGlobalProperties with VB.net on a UWP application

后端 未结 1 1930
刺人心
刺人心 2021-01-29 10:52

I am writing a very simple Universal Windows application with VB in Visual Studio 2017. The application should gave basic network information to the user, so I wanted to collect

1条回答
  •  余生分开走
    2021-01-29 11:22

    Firstly, 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 namespace can be used in uwp app but IPGlobalProperties cannot.

    Secondly you can find equivalent or similar APIs in uwp app. For example you can also find a 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 namespace.

    If you want to get the computer name or domain name as IPGlobalProperties did, you may invoke the GetHostNames() method. Code as follows:

    Imports Windows.Networking.Connectivity
    ''' 
    ''' An empty page that can be used on its own or navigated to within a Frame.
    ''' 
    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
    

    0 讨论(0)
提交回复
热议问题