我想用C#写一个程序,现在可以识别电脑是否通过C#连接到互联网。你能帮我怎么做吗?我不知道该怎么做,因为我不是用C#做网络工作的。
还有一个问题,我如何从c#运行程序并发送参数?
发布于 2010-12-06 07:03:28
使用微软的函数。
你可以用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();
}
}
}https://stackoverflow.com/questions/4362261
复制相似问题