本地连接

qlzf11140820 2009-02-28 03:10:21
C# 中怎么判断本地连接是否连接,如果没连接怎么实现连接??
...全文
113 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
rightyeah 2009-02-28
  • 打赏
  • 举报
回复
up
qlzf11140820 2009-02-28
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 ojlovecd 的回复:]
如果你不知道怎么添加Microsoft Shell Control And Automation引用,请参考一下步骤:
在你的解决方案资源管理器的bin上右键->选择添加引用->选择->COM标签->找到这个引用按确定即可
[/Quote]

你本事太大了!!
我姓区不姓区 2009-02-28
  • 打赏
  • 举报
回复
如果你不知道怎么添加Microsoft Shell Control And Automation引用,请参考一下步骤:
在你的解决方案资源管理器的bin上右键->选择添加引用->选择->COM标签->找到这个引用按确定即可
我姓区不姓区 2009-02-28
  • 打赏
  • 举报
回复
刚才测试一下,可以用:
首先添加Microsoft Shell Control And Automation引用:

static void Main(string[] args)
{
NetWork("本地连接", "启用");//输入你的本地连接名称和要做的操作:启用或停用
}

static void NetWork(string netWorkName, string operation)
{
Shell32.Shell shell = new Shell32.ShellClass();
Shell32.Folder folder = shell.NameSpace(49);
foreach (Shell32.FolderItem fi in folder.Items())
{
if (fi.Name != netWorkName)
continue;
Shell32.ShellFolderItem folderItem = (Shell32.ShellFolderItem)fi;
foreach (Shell32.FolderItemVerb fiv in folderItem.Verbs())
{
if (!fiv.Name.Contains(operation))
continue;
else
{
fiv.DoIt();
Thread.Sleep(1000);
break;
}
}
}
}
qlzf11140820 2009-02-28
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 weilong147247943 的回复:]
引用 8 楼 ojlovecd 的回复:
你能让电脑帮你把网线插上?

汗····
[/Quote]


我是网线插上了 但本地连接处于停用状态 用程序让它启动 ??
weilong147247943 2009-02-28
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 ojlovecd 的回复:]
你能让电脑帮你把网线插上?
[/Quote]
汗····
qlzf11140820 2009-02-28
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 ojlovecd 的回复:]
你能让电脑帮你把网线插上?
[/Quote]

我是是网线插上了 但本地连接处于停用状态 用程序让它启动 ??
qlzf11140820 2009-02-28
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 ojlovecd 的回复:]
你能让电脑帮你把网线插上?
[/Quote]

难道就没任何程序能实现??
我姓区不姓区 2009-02-28
  • 打赏
  • 举报
回复
你能让电脑帮你把网线插上?
qlzf11140820 2009-02-28
  • 打赏
  • 举报
回复
难道就没人知道吗 知道的接分了???
qlzf11140820 2009-02-28
  • 打赏
  • 举报
回复
upupupup
qlzf11140820 2009-02-28
  • 打赏
  • 举报
回复
如果没连接怎么实现连接??
surlew 2009-02-28
  • 打赏
  • 举报
回复
public static bool Ping(string remoteHost)
{
bool Flag = false;
Process proc = new Process();
try
{
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
string dosLine = @"ping -n 1 " + remoteHost;
proc.StandardInput.WriteLine(dosLine);
proc.StandardInput.WriteLine("exit");
while (proc.HasExited == false)
{
proc.WaitForExit(500);
}
string pingResult = proc.StandardOutput.ReadToEnd();
if (pingResult.IndexOf("(0% loss)") != -1)
{
Flag = true;
}
proc.StandardOutput.Close();
}
catch (Exception ex)
{
}
finally
{
try
{
proc.Close();
proc.Dispose();
}
catch
{
}
}
return Flag;
}

remoteHost填写你要ping的服务器
qlzf11140820 2009-02-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 agentianle 的回复:]
如果是说的网线有没有插好:

C# 中怎么判断本地连接是否连接:NetworkInterface.GetIsNetworkAvailable()

如果没连接怎么实现连接:弹出个提示框,提示用户检查网线或网络
[/Quote]

能指教用代码实现 连接吗??
qlzf11140820 2009-02-28
  • 打赏
  • 举报
回复
up 一下 知道的帮帮忙了??
天乐 2009-02-28
  • 打赏
  • 举报
回复
如果是说的网线有没有插好:

C# 中怎么判断本地连接是否连接:NetworkInterface.GetIsNetworkAvailable()

如果没连接怎么实现连接:弹出个提示框,提示用户检查网线或网络

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧