C# Ping 简单使用
作者:freethy 发布于:2015-3-25 15:07 Wednesday
编程过程中,有时候需要判断主机是否在线,最简单的方法就是使用Windows的Ping命令看看能否ping通。看到网上很多文章,说用C#去调用windows的ping.exe,然后解析返回的字符串。我觉得这种方式太麻烦了,就做一下简单判断,不想弄那么麻烦。查了一下,C#专门提供了一个Ping类,与Windows下的ping命令类似:
命令空间: System.Net.NetworkInformation;
使用方法:
bool online = false; //是否在线
Ping ping = new Ping();
PingReply pingReply = ping.Send("192.168.0.201");
if (pingReply.Status == IPStatus.Success)
{
online = true;
ControlUI.AppendLog("已ping通,延时:" + pingReply.RoundtripTime);
}
else
{
ControlUI.AppendLog("ping不通");
}
SqlServer链接远程数据库操作
作者:freethy 发布于:2015-3-25 11:19 Wednesday
--这句是链接一个远程数据库EXEC sp_addlinkedserver '88.88..88.88',N'SQL Server'
--这句是登录远程数据库
EXEC sp_addlinkedsrvlogin '88.88.88.88', 'false', NULL, 'user', 'pwd'
--链接完成后,就可以用以下格式操作远程数据库中的对象
select * from [88.88.88.88].[dbname].[dbo].[table]
通过sql sa用户为系统增加用户
作者:freethy 发布于:2015-3-18 10:35 Wednesday
有sa权限,但忘了系统administrator的密码,可否通过查询分析器,写程序,
在系统中增加administrators组的成员,以可以进入远程电脑!
在系统中增加administrators组的成员,以可以进入远程电脑!
xp_cmdshell 'net user username password /add'
xp_cmdshell 'net localgroup aministrators username /add'
xp_cmdshell 'net localgroup aministrators username /add'
用户名aaa 密码123456
exec [xp_cmdshell] 'net user aaa 123456 /add'
output
命令成功完成。
NULL
NULL
(所影响的行数为 3 行)
output
命令成功完成。
NULL
NULL