1、怎样判断一个网页地址是否能连接的上,例如:http://www.sina.com.cn(30分)2、怎样判断IIS状态,可以重起IIS. (30分)
3、怎样重起本地计算机。 (30分)上边几个问题都是要在winform上实现。贴代码最好。(还有10分自由分)
3、怎样重起本地计算机。 (30分)上边几个问题都是要在winform上实现。贴代码最好。(还有10分自由分)
先拿30分~!
1、
WebRequest myWebRequest=WebRequest.Create("http://www.sina.com.cn");
myWebRequest.Timeout=5000;
try
{
WebResponse myWebResponse=myWebRequest.GetResponse();
Stream resStream = myWebResponse.GetResponseStream();
StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
this.Label1.Text = sr.ReadToEnd();
resStream.Close();
sr.Close();
}
catch(System.Net.WebException xx)
{
this.Label1.Text=xx.Message;
}
连接不上出现异常,显示错误信息,连接的上返回源代码
{
//Detect the Internet,if the pc connected to the Internet,this routine return true,else return false.
bool retVal;
HttpWebRequest myRequest;
HttpWebResponse myResponse;
myRequest = (HttpWebRequest) WebRequest.Create("http://www.sina.com.cn");
myRequest.Timeout = 30000; // 30s
try
{
myResponse = (HttpWebResponse) myRequest.GetResponse();
retVal=true;
}
catch(WebException )
{
retVal=false; }
return retVal;
---------------------------------------------------------------------------------Process.Start ("iisreset /STATUS > a.txt");
Process.Start ("iisreset /REBOOT ");iisreset [computername] /RESTART 停止然后重新启动所有 Internet 服务。
/START 启动所有 Internet 服务。
/STOP 停止所有 Internet 服务。
/REBOOT 重新启动计算机。
/REBOOTONERROR 如果在启动、停止或重新启动 Internet 服务时出错,
则重新启动计算机。
/NOFORCE 如果试图正常停止服务失败,不强制终止 Internet 服务。
/TIMEOUT:val 指定等待 Internet 服务的成功停止的超时值(以秒为单位)。
如果已指定 REBOOTONERROR 参数,超时后可以重新启
动计算机。
服务重新启动的默认值为 20 秒,停止为 60 秒,计算
机重新启动为 0 秒。
/STATUS 显示所有 Internet 服务的状态。
/ENABLE 启用本地系统上 Internet 服务的重新启动。
/DISABLE 禁用本地系统上 Internet 服务的重新启动。