C# want to get network adapter status properties like Duration

First Add reference from Network List Manager 1.0 Type Library

            var manager = new NetworkListManager();
            var connectedNetworks = manager.GetNetworks(NLM_ENUM_NETWORK.NLM_ENUM_NETWORK_CONNECTED).Cast<INetwork>();
            foreach (var network in connectedNetworks)
            {
                if (network.IsConnected)
                {
                  network.GetTimeCreatedAndConnected(out uint _, out uint _, out uint 
                  pdwLowDateTimeConnected, out uint pdwHighDateTimeConnected);

                  DateTime networkConnectedTime = DateTime.FromFileTimeUtc((long) 
                (((ulong)pdwHighDateTimeConnected << 32) | pdwLowDateTimeConnected));

                TimeSpan diff = DateTime.Now.Subtract(networkConnectedTime);

                Console.WriteLine("Name: " + network.GetName() + "  Duration : {0} day(s) {1}:{2}:{3}", diff.Days, diff.Hours, diff.Minutes, diff.Seconds);
                     }
         }

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top