C# 查找网络状态

C# 查找网络状态,c#,C#,我想用C语言编写一个程序,识别计算机是否连接到internet。 你能帮我怎么做吗?我不知道,因为我没有在C#工作 还有一个问题,如何从c#运行程序并发送参数 使用微软的功能 您可以使用p/Invoke调用它: using System; using System.Runtime.InteropServices; namespace ConnectionState { internal class Program { [DllImport("wininet.dl

我想用C语言编写一个程序,识别计算机是否连接到internet。 你能帮我怎么做吗?我不知道,因为我没有在C#工作

还有一个问题,如何从c#运行程序并发送参数

使用微软的功能

您可以使用p/Invoke调用它:

using System;
using System.Runtime.InteropServices;

namespace ConnectionState
{
    internal class Program
    {
        [DllImport("wininet.dll", SetLastError = true)]
        private static extern bool InternetGetConnectedState(out int lpdwFlags, int dwReserved);

        private static void Main(string[] args)
        {
            int flags;
            bool isConnected = InternetGetConnectedState(out flags, 0);
            Console.WriteLine(string.Format("Is connected: {0} Flags:{1}", isConnected, flags));
            Console.Read();
        }
    }
}
使用微软的功能

您可以使用p/Invoke调用它:

using System;
using System.Runtime.InteropServices;

namespace ConnectionState
{
    internal class Program
    {
        [DllImport("wininet.dll", SetLastError = true)]
        private static extern bool InternetGetConnectedState(out int lpdwFlags, int dwReserved);

        private static void Main(string[] args)
        {
            int flags;
            bool isConnected = InternetGetConnectedState(out flags, 0);
            Console.WriteLine(string.Format("Is connected: {0} Flags:{1}", isConnected, flags));
            Console.Read();
        }
    }
}

问题#2:更好。自迁移以来,这是一个副本:问题#2:更好。自迁移以来,这是一个副本: