首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >查找网络状态

查找网络状态
EN

Stack Overflow用户
提问于 2010-12-06 06:13:39
回答 1查看 135关注 0票数 1

我想用C#写一个程序,现在可以识别电脑是否通过C#连接到互联网。你能帮我怎么做吗?我不知道该怎么做,因为我不是用C#做网络工作的。

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-12-06 07:03:28

使用微软的函数。

你可以用P/Invoke来调用它:

代码语言:javascript
复制
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();
        }
    }
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4362261

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档